...

View Full Version : sql query help please!!



LJackson
03-05-2009, 03:16 PM
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

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

$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

guelphdad
03-05-2009, 03:42 PM
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:



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

LJackson
03-05-2009, 03:52 PM
Hi guelphdad,

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


$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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum