danIT Posted January 9, 2009 Posted January 9, 2009 I have a table full of statements teachers use to write there reports. they want all statements to begin with the students name (this code has been sorted) but to do this i need all the statements to start with '--fristname' How can i add '--firstname' to the beginning of all the strings stored in the table?
powdarrmonkey Posted January 9, 2009 Posted January 9, 2009 Assumption: each row has a unique id, and you have already established a connection called db. (disclaimer: I haven't tested this.) $sub = '--firstname'; $table = 'mytable'; $getsql = "SELECT id, name FROM {$table}"; $getresult = mysql_query($getsql, $db); while($row = mysql_fetch_array($getresult)) { $sql = "UPDATE {$table} SET `name`='{$sub}{$row[1]}' WHERE `id`=${row[0]} LIMIT 1"; if( ! mysql_query($sql, $db) ) print("Unable to update row {$row[0]}\n"; }
webman Posted January 9, 2009 Posted January 9, 2009 (edited) OK, try this on a test table first (using Concat) : UPDATE statements SET statement = CONCAT('--firstname', statement) Edited January 9, 2009 by webman Mis-read original post, oops! 2
powdarrmonkey Posted January 9, 2009 Posted January 9, 2009 Thought it could probably do something like that, but I've just never had time to learn
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now