Darkmatter5 Posted April 7, 2009 Share Posted April 7, 2009 Here's my code: $query1="UPDATE games SET title='$_POST[title]', descr='$_POST[descr]' WHERE game_id=$rowcon[game_id]"; $query2="UPDATE game_genres SET genre_id='$_POST[genre]' WHERE game_id=$rowcon[game_id]"; for($i=1;$i<=2;$i++) { $result=mysql_query($query."$i") or die(mysql_error()); } How can I get the mysql_query to run "mysql_query($query1)" and "mysql_query($query2)"? Quote Link to comment https://forums.phpfreaks.com/topic/153005-help-with-variables-and-combining-variables/ Share on other sites More sharing options...
premiso Posted April 7, 2009 Share Posted April 7, 2009 Use arrays <?php $querys=array(); $querys[]="UPDATE games SET title='$_POST[title]', descr='$_POST[descr]' WHERE game_id=$rowcon[game_id]"; $querys[]="UPDATE game_genres SET genre_id='$_POST[genre]' WHERE game_id=$rowcon[game_id]"; foreach ($querys as $sql) { $result = mysql_query($sql) or die(mysql_error()); } ?> The other method would be something like this: $query1="UPDATE games SET title='$_POST[title]', descr='$_POST[descr]' WHERE game_id=$rowcon[game_id]"; $query2="UPDATE game_genres SET genre_id='$_POST[genre]' WHERE game_id=$rowcon[game_id]"; for($i=1;$i<=2;$i++) { $result=mysql_query(${"query" . $i}) or die(mysql_error()); } But I would suggest using arrays. Quote Link to comment https://forums.phpfreaks.com/topic/153005-help-with-variables-and-combining-variables/#findComment-803606 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.