danIT (9th January 2009), powdarrmonkey (9th January 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?

Assumption: each row has a unique id, and you have already established a connection called db.
(disclaimer: I haven't tested this.)
Code:$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"; }

OK, try this on a test table first (using Concat) :
Code:UPDATE statements SET statement = CONCAT('--firstname', statement)
Last edited by webman; 9th January 2009 at 07:17 PM. Reason: Mis-read original post, oops!
danIT (9th January 2009), powdarrmonkey (9th January 2009)

Thought it could probably do something like that, but I've just never had time to learn![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)