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 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation sql query help please!!

    Hi,

    I am having trouble with my sql code, i have correct query but i want to condense it if possible and get my php page to perform the query.

    here are the querys
    Code:
    UPDATE ratings SET used_ips = 'NULL',total_value = '0',total_votes = '0' WHERE id = 'valuetemp';
            UPDATE ratings SET used_ips = 'NULL',total_value = '0',total_votes = '0' WHERE id = 'easeofusetemp';
            UPDATE ratings SET used_ips = 'NULL',total_value = '0',total_votes = '0' WHERE id = 'deliverytemp';
            UPDATE ratings SET used_ips = 'NULL',total_value = '0',total_votes = '0' WHERE id = 'delchargetemp';
    but im not sure how to use this data,

    usually i would update one record which i can handle by doing
    PHP Code:
    $sql ="UPDATE ratings SET used_ips = 'NULL',total_value = '0',total_votes = '0' WHERE id = 'easeofusetemp'";
    $query mysql_query($sql); 
    but im not sure if i will have to run 4 individual queries as above or if it can be done in one query

    if anyone can help
    thanks
    Luke

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Don't use 'NULL' inside quotes, that is a string and not an actual NULL value. Similarly you should not quote numeric values.

    Lastly, since you are updating all values to the same thing then you can change your query to:

    Code:
    UPDATE ratings 
      SET 
        used_ips = NULL,
        total_value = 0,
        total_votes = 0 
      WHERE 
      id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp')
    ;

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    Hi guelphdad,

    thanks for your reply, so with your example can i do

    PHP Code:
    $sql="UPDATE ratings 
      SET 
        used_ips = NULL,
        total_value = 0,
        total_votes = 0 
      WHERE 
      id IN ('valuetemp', 'easeofusetemp', 'deliverytemp', 'delchargetemp');
              $query = mysql_query($sql); 
    cheers
    Luke


  •  

    Posting Permissions

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