I have a pile of drop downs on one page. They are generated based upon tables in a database. After searching, the user needs to be able to refine their search. They click a form button and go back to the original search page with all the fields retaining the values of the original search. Everything works GREAT except my drop downs! They refuse to remember anything!
here is the code:
<?php
$ddmenutable="";
$ddmenuname="";
$ddmenuvisible="";
$ddmenuvalue="";
$ddmenuorder="";
$ddmenuhyphensqty="";
$ddmenuselectvalue="";
$selected="";
function find_value($particular_field)
{
echo $particular_field;
}
function ddmenuhyphens($ddmenuhyphensqty){
$mxpx="1";
while ($mxpx <= $ddmenuhyphensqty)
{
echo "-";
$mxpx++;
};
};
function ddmenu($ddmenuselectvalue,$ddmenuname,$ddmenutable,$ddmenuvisible,$ddmenuvalue,$ddmenuorder,$ddmenuhyphensqty){
/*---------------------------------------------------------*/
/* The following test line prints out the correct */
/* value for the variable! And the thing still don't work! */
/*---------------------------------------------------------*/
echo $ddmenuselectvalue;
$query1 = "select $ddmenuvisible from $ddmenutable" ;
$query1 = stripSlashes($query1) ;
$result1 = mysql_query($query1);
$query2 = "select $ddmenuvalue from $ddmenutable" ;
$query2 = stripSlashes($query2) ;
$result2 = mysql_query($query2);
if ($result1==0 or $result2==0)
echo("<b>Error ".mysql_errno().": ".mysql_error()."</b>");
elseif (@mysql_num_rows($result1) == 0)
echo("<b>No Information</b><br>");
else
{
for ($i = 0; $i <mysql_num_fields($result1); $i++)
{
echo "<select size=1 name=" . $ddmenuname . " style='font-family: Arial, sans-serif; font-size: 7pt'>
<option value=''>";
ddmenuhyphens($ddmenuhyphensqty);
echo "</option>\n";
}
for ($i = 0; $i < mysql_num_rows($result1); $i++)
{
$rowvisible = mysql_fetch_row($result1);
for ($j = 0; $j < mysql_num_fields($result1); $j++);
$rowvalue = mysql_fetch_row($result2);
for ($j = 0; $j < mysql_num_fields($result2); $j++)
{ if ($rowvalue[$j] == $ddmenuselectvalue)
{ $selected = 'selected'; }
echo "<option " . $selected . " value=\"" . $rowvalue[$j] . "\">" . $rowvisible[$j] . "</option>\n";
$selected = "";
}
}
echo "</select>";
}};
?>
.......
<?php ddmenu(find_value($propertyownershipdirection1),propertyownershipdirection1,lp_dir,lp_dir_desc,lp_dir,id,2); ?>
In the final line, If I substitute an actual value for the function find_value($propertyownershipdirection1)... (like 'E' for East), then the code works great. I know it's being accurately remembered because it echos correctly (as you can see by my comments above).
So why on earth is my code not working?
ANY HELP AT ALL WOULD BE AWESOME!!!!!!!