...

View Full Version : Using PHP IF and SQL



Vernk
10-08-2012, 02:39 AM
Hello , I am trying to achieve something like this :


cornjob.php

<?php
mysql_query("SELECT * FROM userinfo WHERE IF timeleft = 0 THEN SET plan=0");

?>

How can I do something like this with PHP or SQL?

Fou-Lu
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.

Vernk
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

Fou-Lu
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum