View Full Version : PHP/MySQL problem..anyone?

04-04-2003, 06:33 AM
If i wanted to increment a database column's values (all of them) by one, every time a script ran...why won't this work? :(

// mysql_pconnect("host", "user", "password");
// mysql_select_db("database");
// $result = mysql_query('select column from database');
// @ $num_results = mysql_num_rows($result);
// mysql_query("update database set column = '$result'+1");

Can anyone help please, I'm stuck..tried everything I can think of but still no go :(

04-04-2003, 07:57 AM
there's a database called database and a table called database?

other than that, just amend the update call

mysql_query("UPDATE database SET column=" .($result+1));

and if in future you get bad queries, just sling
echo mysql_error();
after the calls to point you in the right direction.

04-04-2003, 09:55 AM
oops, yeah, the table should have been "table", i was just illustrating lol, rushed through it

and still not working..no matter what value i start with in the columns, it sets them all to 3..? what the? lol...

(for the record - it's not spitting out an error, just not incrementing the numbers in that column by one like it should)

04-04-2003, 10:35 AM
it might be that $result is always returning as 2 and 2+1 = 3.

perhaps just use an update without a prior select

"UPDATE table SET column=column+1";

04-04-2003, 10:43 AM
OK nevermind guys..I got it sorted :D

//mysql_pconnect("host", "user", "password");
//$query = "select * from table";
//$result = mysql_query($query);
//$num = mysql_numrows($result);
//$variablearray = mysql_fetch_array($result);
//$currentvalue = $variablearray["column"];

//mysql_query("UPDATE table SET column=" .($currentvalue+1));

sooooo simple, i don't know what i was doing with that first one lol :rolleyes: And yes i'm going to clean all the junk out of that too :p

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum