Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post

    Using PHP IF and SQL

    Hello , I am trying to achieve something like this :
    PHP Code:
    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?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You mean like an update query?
    Code:
    UPDATE userinfo SET plan = 0 WHERE timeleft = 0
    ?

    SQL has its own if/else handling, look into the case syntax. Much like a switch really.

  • #3
    Regular Coder
    Join Date
    Oct 2011
    Posts
    113
    Thanks
    9
    Thanked 1 Time in 1 Post
    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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •