Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/214705-php-mysql_fetch_array-query/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.