chained select ???
Posted: Sun Aug 12, 2007 8:14 am
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello
i have a script that get records from mysql by letters
i need to modified it that all the select box values will be from mysql
and one change the other
thanks
this is my basic scriptCode: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<?PHP
include("connecttomysql.php");
?>
<FORM NAME="form1" METHOD="GET" ACTION="select_TEST_R.php">
<p align="center">
<SELECT NAME="AreaID" onChange="LoadCities();">
<option value="0">Sorting by Letters</option>
<option value='1'>A-E</option>
<option value='2'>F-J</option>
<option value='3'>K-O</option>
<option value='4'>P-T</option>
<option value='5'>U-Z</option>
</SELECT>
<BR>
<BR>
<SELECT NAME="CityID" >
<OPTION value="0">Select City</OPTION>
<?PHP
$query0 = "SELECT * FROM uk_area ORDER BY name"; // display all citys
$result0 = mysql_query($query0)
or die ("query failed: ".mysql_error());
while ($row0 = mysql_fetch_array($result0))
{echo "<option value=",$row0['number'],">",$row0['name'],"</option>";
}
?>
</SELECT>
<SCRIPT language=JavaScript type=text/javascript>
<!--
var areaid = new Array();
var cityid = new Array();
var title = new Array();
<?PHP
$x = '0'; // counter for the java areaid cityid title
$query1 = "SELECT * FROM uk_area WHERE name <'F' ORDER BY name"; // A - E
$result1 = mysql_query($query1)
or die ("query failed: ".mysql_error());
while ($row1 = mysql_fetch_array($result1))
{
echo "areaid[$x] ='1';";
echo "cityid[$x] ='",$row1['number'],"';";
echo "title[$x] = '",$row1['name'],"';";
$x++;
}
//---------------------------------------------------
$query2 = "SELECT * FROM uk_area WHERE name > 'E' AND name <'K' ORDER BY name"; // F - J
$result2 = mysql_query($query2)
or die ("query failed: ".mysql_error());
while ($row2 = mysql_fetch_array($result2))
{
echo "areaid[$x] ='2';";
echo "cityid[$x] ='",$row2['number'],"';";
echo "title[$x] = '",$row2['name'],"';";
$x++;
}
//---------------------------------------------------
$query3 = "SELECT * FROM uk_area WHERE name > 'J' AND name <'P' ORDER BY name"; // K - O
$result3 = mysql_query($query3)
or die ("query failed: ".mysql_error());
while ($row3 = mysql_fetch_array($result3))
{
echo "areaid[$x] ='3';";
echo "cityid[$x] ='",$row3['number'],"';";
echo "title[$x] = '",$row3['name'],"';";
$x++;
}
//---------------------------------------------------
$query4 = "SELECT * FROM uk_area WHERE name > 'O' AND name <'U' ORDER BY name"; // P - T
$result4 = mysql_query($query4)
or die ("query failed: ".mysql_error());
while ($row4 = mysql_fetch_array($result4))
{
echo "areaid[$x] ='4';";
echo "cityid[$x] ='",$row4['number'],"';";
echo "title[$x] = '",$row4['name'],"';";
$x++;
}
//---------------------------------------------------
$query5 = "SELECT * FROM uk_area WHERE name > 'T' ORDER BY name"; // U - Z
$result5 = mysql_query($query5)
or die ("query failed: ".mysql_error());
while ($row5 = mysql_fetch_array($result5))
{
echo "areaid[$x] ='5';";
echo "cityid[$x] ='",$row5['number'],"';";
echo "title[$x] = '",$row5['name'],"';";
$x++;
}
?>
<!-- the select box script , must be neer </body> -->
function LoadCities(m)
{
var area;
area = document.form1.AreaID.options[document.form1.AreaID.selectedIndex].value
var LengthArray
LengthArray = document.form1.AreaID.length
var i;
var k=0;
for (i=0;i < areaid.length ; i++){
if (area == areaid[i])
k++;
}
document.form1.CityID.length = k + 1
//alert("k="+k);
k=1 ;
for (i=0;i < areaid.length ; i++){
if (area == areaid[i]){
if (title[i] != ''){
document.form1.CityID.options[k].text = title[i];
document.form1.CityID.options[k].value = cityid[i];
k++
}
}
}
document.form1.CityID.value='0';
if( m )
document.form1.CityID.value = m;
}
document.form1.CityID.value='0';
<!-- END -- the select box script , must be neer </body> -->
</SCRIPT>
<BR><BR>
<input type="submit" name="Submit" value="Submit">
</FORM>
<?PHP
// disconect from mysql
mysql_close($connection);
?>
</body>
</html>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]