Can somebody help me to solve this problem?
I want to make two dynamic dropdown menu. One of menu can affect what the other shown. It is the first time I use php, hoping that someone can help me to solve.
#php code
$query1 = "SELECT brandname FROM BRAND_ALL_NAME";
$result1 = mysql_query($query1);
$rows1 = mysql_num_rows($result1);
while($rec_set1 = mysql_fetch_array($result1, MYSQL_NUM)) {
$j = 0;
$query2 = "SELECT DISTINCT model, specific FROM PROD_INFO WHERE brandname ='".$rec_set1."'";
$result2 = mysql_query($query2);
$rows2 = mysql_num_rows($result2);
while($rec_set2 = mysql_fetch_array($result2, MYSQL_NUM)) {
${"arrBrand".$i}[$j++] = $rec_set2[0]."".$rec_set2[1];
}
$i++;
}
for($lgth1=0; $lgth1 < $rows1; $lgth1++) {
for($lgth2=0; $lgth2 < count(${"arrBrand".$lgth1}); $lgth2++) {
$arrModSpec[$lgth1][$lgth2] = ${"arrBrand".$lgth1}[$lgth2];
}
}
#javascript code
echo "<script language=\"javascript\">";
echo "function handleChange(".$newDisplay.") {";
if($newDisplay >=0 ) {
$NumEntries = count($arrModSpec[$newDisplay]);
for($incre=1; $incre <= $NumEntries; $incre++) {
echo "modspecif.options[".$incre."] = new option(".$arrModSpecif[$newDisplay][$incre - 1].", ".$incre.")";
}
}
echo " modspecif.selectedIndex = 0";
echo "}";
echo "</script>";
#html code
<SELECT name="bndname" OnClick="handleChange(<?php $bndname ?>)">
<OPTION value="-1" selected> -- Please Choose one --
<?php
$k = 0;
$query_temp1 = "SELECT DISTINCT brandname FROM PROD_INFO WHERE product ='".$rec_set_prod[0]."'";
$result_temp1 = mysql_query($query_temp1);
$rows_temp1 = mysql_num_rows($result_temp1);
if($rows_temp1 > 0) {
$k = 0;
while($rec_set_temp1 = mysql_fetch_array($result_temp1,MYSQL_NUM)) {
echo "<option value=".$k++.">".$rec_set_temp1[0]." </option>";
}
}
?>
</SELECT>
<select name="modspecif">
<option value="-1"> -- Please Choose one --
<option>
<option>
<option>
<option>
</select>
I click the dropdown that IE has an error icon on left hand bottom corner ("!" in a triangle).
Can I use php code inside javascript? How can I pass the php variables? Do I need to store the php array as javascript array?
Many and many problems I have, can anyone help to post the exist code or modify my code....thx thx a lot >3<