View Full Version : Using PHP IF and SQL
10-08-2012, 02:39 AM
Hello , I am trying to achieve something like this :
mysql_query("SELECT * FROM userinfo WHERE IF timeleft = 0 THEN SET plan=0");
How can I do something like this with PHP or SQL?
10-08-2012, 04:48 AM
You mean like an update query?
UPDATE userinfo SET plan = 0 WHERE timeleft = 0
SQL has its own if/else handling, look into the case (http://dev.mysql.com/doc/refman/5.0/en/case.html) syntax. Much like a switch really.
10-08-2012, 05:44 AM
Well I want it to select the timeleft and if it equals 0 then it will set plan to 0 so some way of doing this
10-08-2012, 07:49 AM
Do you need to make use of them after the fact? You cannot issue a select and an update together (especially not in PHP since they are different DMS'). If you don't need to make use of them, you can simply update. Otherwise, select with a necessary where clause to capture the data, then issue an update.
Unless `plan` isn't a property?
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.