chained select ???

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

chained select ???

Post by giliat »

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 script

Code: 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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: chained select ???

Post by superdezign »

giliat wrote: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
I think you need to be more specific as to what you have done so far and what your script isn't doing that you want it to.
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

Post by giliat »

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]


this is what need to do
i need to deved citys by area if area selected as defult all the citys will display

this is what i did but its not separate the citys

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<?PHP
include("dira4memysql.php"); 

?>
<FORM NAME="form1" METHOD="GET" ACTION="select_TEST_R.php">




  <p align="center">
  <SELECT NAME="AreaID" onChange="LoadCities();">
    <option value="0">all area</option>
    <?PHP
$query0 = "SELECT * FROM area ORDER BY name"; // display all citys
mysql_query( "SET NAMES 'utf8'"); 
$result0 = mysql_query($query0)
or die ("query failed: ".mysql_error());
$allarea= mysql_num_rows($result0);
while ($row0 = mysql_fetch_array($result0))
{

echo "<option value=",$row0['number'],">",$row0['name'],"</option>";

}

?>
  </SELECT>
  <BR>
  <BR>
  <SELECT NAME="CityID" >
    <OPTION value="0">all citys</OPTION>
 <?PHP
$querycity = "SELECT * FROM city ORDER BY name"; // display all citys
mysql_query( "SET NAMES 'utf8'"); 
$resultcity = mysql_query($querycity)
or die ("query failed: ".mysql_error());
while ($rowcity = mysql_fetch_array($resultcity))
{echo "<option value=",$rowcity['city_code'],">",$rowcity['name'],"</option>";

}
?>
  </SELECT>
    
    
    
    
    
  <SCRIPT language=JavaScript type=text/javascript>
<!--
		var areaid = new Array();
		var cityid = new Array();
		var title = new Array();

<?PHP
if(!isset ($x)){$x = '0';} 
$query1 = "SELECT * FROM city  ORDER BY name"; 
mysql_query( "SET NAMES 'utf8'"); 
$result1 = mysql_query($query1)
or die ("query failed: ".mysql_error());

while ($row1 = mysql_fetch_array($result1))
{
echo "areaid[$x] ='",$row1['area'],"';";
echo "cityid[$x] ='",$row1['city_code'],"';";
echo "title[$x] = '",$row1['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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

giliat wrote:i need to deved citys by area if area selected as defult all the citys will display

this is what i did but its not separate the citys
You're not getting what I meant by 'specific.' We don't need to see your whole page, only the part that's causing problems. We're not going to rewrite your whole script for you.
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

this is all 1 script

Post by giliat »

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]


the part that changes sould be this

Code: Select all

<?PHP 
if(!isset ($x)){$x = '0';} 
$query1 = "SELECT * FROM city  ORDER BY name"; 
mysql_query( "SET NAMES 'utf8'"); 
$result1 = mysql_query($query1) 
or die ("query failed: ".mysql_error()); 

while ($row1 = mysql_fetch_array($result1)) 
{ 
echo "areaid[$x] ='",$row1['area'],"';"; 
echo "cityid[$x] ='",$row1['city_code'],"';"; 
echo "title[$x] = '",$row1['name'],"';"; 
$x++; 
}

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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

And like I said before.. What is your code doing, and what isn't it doing that you want it to? I have no idea what you are trying to accomplish with this code, or what it is doing because to me.. It doesn't look like it's doing anything but printing debugging data.
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

get the area names into select box

Post by giliat »

the area code = value from selected area name sould modified the city select box to display only the citys in the selected area
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: get the area names into select box

Post by superdezign »

giliat wrote:the area code = value from selected area name sould modified the city select box to display only the citys in the selected area
Could you please stop telling me what you want it do and tell me what it actually does?
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

Post by giliat »

any area that i set it display all the citys not only the citys in that area


thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

giliat wrote:any area that i set it display all the citys not only the citys in that area
Maybe you should try a WHERE condition on your SQL query that corresponds to the selected area.
giliat
Forum Commoner
Posts: 28
Joined: Sun May 20, 2007 2:00 pm

Post by giliat »

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]


when i try do add WHERE like this:

Code: Select all

<?PHP
if(!isset ($x)){$x = '0';} 
$area_number=$row0['number'],">",;
$query1 = "SELECT * FROM city WHERE area='$area_number' ORDER BY name"; 
mysql_query( "SET NAMES 'utf8'"); 
$result1 = mysql_query($query1)
or die ("query failed: ".mysql_error());

while ($row1 = mysql_fetch_array($result1))
{
echo "areaid[$x] ='",$row1['area'],"';";
echo "cityid[$x] ='",$row1['city_code'],"';";
echo "title[$x] = '",$row1['name'],"';";
$x++;
}

?>
i got nothing in the city select box :roll:


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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Have you tried debugging by echoing out the query? And what is the value of $area_number and where does it come from?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

giliat, please read your waiting private message.
Post Reply