For loop using functions : Repeating code
Posted: Tue May 31, 2005 7:15 am
Hi,
I have 20 functions which call sqlqueries and creates drop down menus.
// Code to add to repeating table contents :
So should something like the following work? Any ideas?
I have 20 functions which call sqlqueries and creates drop down menus.
// Code to add to repeating table contents :
Code: Select all
<? func1() ?>
function func1() {
$sql_query = mysql_query("SELECT suitType, suitabilityId FROM ausuitability");
echo "<select name=\"suitabilityId\">";
echo "<option value=\"\">-- Select Option --</option>";
while(list($suitName, $suitabilityId)=mysql_fetch_array($sql_query)) {
$suitName = stripslashes($suitName);
echo "<option value=\"$suitabilityId\">$suitName</option>";
}
echo "</select>";
mysql_free_result($sql_query);
}Code: Select all
$dsc=array('1st','2nd');
$named = array(func1(),func1());
for($x = 0; $x<count($dsc); $x++)
{
if($x % 2)
{
echo "<tr class=\"row1\">\n";
}
else
{
echo "<tr class=\"row2\">\n";
}
echo "<td width=\"200px\" colspan=\"2\" valign=\"top\">".$dsc[$x]."</td>\n";
echo "<td width=\"200px\" colspan=\"2\">".$named[$x]."</td></tr>\n";
}