I need to send the value of ['sno'] from $result2 to process.php
Code: Select all
<?php
include ('functions_new.php5');
echo getHeaderCrown();
if (!isset($passed_value)){ $passed_value=1;}
if (!isset($passed_value2)){ $passed_value2=1;}
?>
<body onload="redirect(<?php echo $passed_value.','.$passed_value2?>,2)">
<?php
include('con.php');
$sql="select * from categories";
$sql2="select * from subcategories WHERE categ=".$passed_value;
$result=mysql_query($sql,$id_link) or die (mysql_error());
$result2=mysql_query($sql2,$id_link) or die (mysql_error());
?>
<form name="doublecombo">
<label for="example">Select the CATEGORY here:</label>
<select id="example" name="example" size="1" onChange="redirect(this.options.selectedIndex,<?php echo $passed_value.','.$passed_value2?>)">
<option>-select-</option>
<?php
while ($newarray=mysql_fetch_array($result)) {
echo '<option value="'.$newarray['sno'].'" ';
if ($newarray['sno']==$passed_value) {echo "SELECTED";};
echo '>'.$newarray['categories'].'</option>'.'\n';
}
?>
</select>
<label for="stage2">Select the SUB-CATEGORY here:</label>
<select id="stage2" name="stage2" size="1">
<?php
while ($newarray=mysql_fetch_array($result2)) {
echo '<option value="'.$newarray['sno'].'" ';
if ($newarray['sno']==$passed_value2) {echo "SELECTED";};
echo '>'.$newarray['scategories'].'</option>';
$x=$x+1;}
?>
</select>
<input type="button" name="test" value="Submit" onClick="go()" />
<script>
<!--
/*
The original JScript can be found in nearly every JScript website
I'm just mentioning one
Courtesy of SimplytheBest.net - http://simplythebest.net
*/
var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++){
group[i]=new Array
}
<?php
//Here comes the data from the two linked tables in a format suited for JScripting
// into the script mentioned here above
$sql="select * from categories";
$result=mysql_query($sql,$id_link) or die (mysql_error());
$x=0;$y=0;$m=0;$z=1;
while ($newarray=mysql_fetch_array($result)) {
echo "group[0][$m]=new Option(\"".$newarray['categories'].'","'.$newarray['sno'].'")'."\n";
$sql2="select * from subcategories WHERE categ=".$newarray['sno']." order by sno asc";
$result2=mysql_query($sql2,$id_link) or die (mysql_error());
while ($newarray2=mysql_fetch_array($result2)) {
echo "group[$z][$y]=new Option(\"".$newarray2['scategories'].'","'.$newarray2['sno'].'")'."\n";
$y=$y+1;
}
$z=$z+1;
$y=0;
$m=$m+1;
}
?>
var temp=document.doublecombo.stage2
function redirect(x,d,f){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[eval(x)][i].text,group[eval(x)][i].value)
}
temp.options[d].selected=true
}
//-->
</script>
</form>
<?php
echo getFooter();
?>