acctman Posted September 29, 2010 Share Posted September 29, 2010 Hi i'm trying to process the mysql_fetch_array query below and simplify the code so only 1 query is ran for both sets, is that possible <select name=[set1]> <?php $set1 = mysql_fetch_array(mysql_query("SELECT `Locale` FROM `language` WHERE `Setting` = '1' ORDER BY FormatSet")); while($row = $set1){ echo "<option value=\"$set1\">$set1</option>\n"; } ?> </select> <select name=[set2]> <?php $set2 = mysql_fetch_array(mysql_query("SELECT `Locale` FROM `language` WHERE `Setting` = '2' ORDER BY FormatSet")); while($row = $set2){ echo "<option value=\"$set2\">$set2</option>\n"; } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/214705-php-mysql_fetch_array-query/ Share on other sites More sharing options...
kickstart Posted September 29, 2010 Share Posted September 29, 2010 Hi Quite a few ways to do it. For example you could try something like this:- <?php $SetArray = array('1'=>array(),'2'=>array()); $set = mysql_query("SELECT Setting, Locale FROM language WHERE Setting IN ('1','2') ORDER BY FormatSet"); while($row = mysql_fetch_array($set)) { $SetArray[$row['Setting']][] = "<option value='".$row['Locale']."'>".$row['Locale']."</option>"; } echo "<select name='set1'>".implode("\n",$SetArray['1'])."</select>" echo "<select name='set2'>".implode("\n",$SetArray['2'])."</select>" ?> Stores the options in a pair of arrays, then implodes the arrays at the end to echo them out. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/214705-php-mysql_fetch_array-query/#findComment-1117106 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.