Page 1 of 1

go through each column in table and update

Posted: Sun Oct 02, 2005 4:30 am
by ecaandrew
I am trying to figure out how to do something with php.
basically i have a table with the fields user_id,friend_id,new

i want it to to go through each row where USER_ID = 5 and update the new field to "1"


so far i have something like this

Code: Select all

if ($row_profile_count > 0) {
$sql = mysql_query("select * from friends where userid='".$_SESSION['session_id']."'");


i know it should be a foreach statement i think


}

Posted: Sun Oct 02, 2005 4:47 am
by mickd
why not just

Code: Select all

mysql_query("UPDATE friends SET new=1 WHERE USER_ID=5");

Posted: Sun Oct 02, 2005 4:51 am
by ecaandrew
because there will be multiple rows

it will need to be like this

Code: Select all

UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='1'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='2'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='3'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='4'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='5'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='6'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='7'
UPDATE friends SET new='1' WHERE userid='USER_ID' AND friendid='8'
its going to need to go through a series depending how many are in the database, i know it should be a foreach

Posted: Sun Oct 02, 2005 4:56 am
by mickd
above what i wrote should update all that have user_id 5.