Jump to content

php mysql_fetch_array query


acctman

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.