I am not sure I understand the problem, but I'll try. You want to build 28 drop-down lists from 28 dynamic different queries on the database. And you don't want to write 28 different functions in your code. Right?
You can handle this by having your queries stored in an array, so you can pull them one by one. Actually it is a 2-dimensional array, so you can also store the text shown before the drop down box and the name of the select. The latter so you can handle the responses via the name of the select box.
I assume that you use the same database for each query! Otherwise you have to store the dbname in the array also. Example of your code (sorry for the make-up changes but I like structured code):[php]
<?php
$queries = array(
array('text' => "Select home",
'query' => "SELECT home,homenum FROM ohcn_homes ORDER BY home",
'selname' => "homes"),
array('text' => "Select myhome",
'query' => "SELECT myhome,myhomenum FROM my_homes ORDER BY myhome",
'selname' => "myhomes"),
array('text' => "Select col1",
'query' => "SELECT col1, col2 FROM other_table ORDER BY col1",
'selname' => "cols")
);
include 'includes/db.inc';
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) {
echo("Server connection failed : " . mysql_error() . "\n");
}
mysql_connect_db($db, $cid) {
or die("Connect to db failed: " . mysql_error());
}
echo '<html><head><title>Select test</title></head><body>';
// -----------------------------------------------------------
// loop through $SQL array, select data and make dropdown list
// -----------------------------------------------------------
for ($i=0; $i < count($queries); $i++) {
echo "<label style='width:100px;'>{$queries[$i]['text']}</label><select style='width:100px;' name='" . $queries[$i]['selname'] . "'>";
$retid = mysql_query($queries[$i]['query']);
if (!$retid) {
die("Select failed on: {$queries[$i]['query']} MySQL error=" . mysql_error());
} // End IF
else {
while ($row = mysql_fetch_array($retid)) {
/* display menu items */
echo "<OPTION VALUE='{$row[0]}'>{$row[1]}</OPTION>";
} // End WHILE
echo '</select><br />';
}
} // end FOR
echo '</body></html>';
?>[/php]Ronald :cool: