webguync Posted March 23, 2010 Share Posted March 23, 2010 is it ok to use multiple $query and $result for different SQL statements? for example: $query = "SELECT username,pwid,name,user_id FROM roster WHERE pwid = '$pwid' AND username='$username'"; $result = mysql_query($query) or die(mysql_error()); and further down the page... $query = "UPDATE roster SET login_timestamp = DATE_ADD(NOW(), INTERVAL 3 HOUR) WHERE username = '$username' AND pwid = '$pwid' "; //echo $query; //for debugging test $result = mysql_query($query) or die(mysql_error()); ...even further down the page $query = "DELETE FROM log WHERE user_id = $user_id AND roster.user_id = $user_id"; //echo $query; //for debugging test $result = mysql_query($query) or die(mysql_error()); or would I need to change to $query1,$result1,$query2,$result2,$query3,$result3? Quote Link to comment Share on other sites More sharing options...
o3d Posted March 23, 2010 Share Posted March 23, 2010 You will need to use different $result variables. When you loop through your dataset (the select statement) and you issue an update/delete/select query it will override the initial $result variable. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted March 23, 2010 Share Posted March 23, 2010 you can use the same variable numerous times, but remember: every time you re-declare a variable, it loses it's old values. Set a unique variable to hold each result set. Quote Link to comment Share on other sites More sharing options...
webguync Posted March 23, 2010 Author Share Posted March 23, 2010 thanks, is it best to do a variable that describes the query? eg: $query_select, $result_select, $query_update, $result_update etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.