Jump to content

Recommended Posts

Posted

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?

Posted

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";
}

Posted (edited)

OK, try this on a test table first (using Concat) :

 

UPDATE statements SET statement = CONCAT('--firstname', statement)

Edited by webman
Mis-read original post, oops!
  • Thanks 2

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...