How to update random row in database using rand() with where clause
Here is what I am trying right now, its not working not sure whats wrong
mysql_query("UPDATE `user` SET `token` = '$session' WHERE NOT toke = '1' limit 1 rand()");
How to update random row in database using rand() with where clause
Here is what I am trying right now, its not working not sure whats wrong
mysql_query("UPDATE `user` SET `token` = '$session' WHERE NOT toke = '1' limit 1 rand()");
Your query is not valid. First of all there is a typo in it, toke
should be token
. WHERE NOT
should be WHERE token <> '1'
. You can indeed use RAND()
, but with on ORDER BY
clause. So your query should look like this:
mysql_query("UPDATE `user` SET `token` = '$session' WHERE `token` <> '1' ORDER BY RAND() LIMIT 1");