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? Link to comment https://forums.phpfreaks.com/topic/196289-multiple-query-and-result-on-the-same-page/ 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. Link to comment https://forums.phpfreaks.com/topic/196289-multiple-query-and-result-on-the-same-page/#findComment-1030756 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. Link to comment https://forums.phpfreaks.com/topic/196289-multiple-query-and-result-on-the-same-page/#findComment-1030757 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. Link to comment https://forums.phpfreaks.com/topic/196289-multiple-query-and-result-on-the-same-page/#findComment-1030760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.