relation two listbox

General discussions related to php

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jan 26, 2012 3:14 am

relation two listbox

Postby msasan1367 » Fri Jul 20, 2012 5:58 am

I write this code now I want connect 2 list box to each other and when I select an option in first link box, just show its related data in second

please help me

Code: Select all

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Select Cities</title>


<td colspan=”2″>Religion</TD>
<select name="items">
<option value="">Choose province</option>
$conn=mysql_connect("", "university", "123456") ;
mysql_select_db("university",$conn) or die ("error cannot connect");

$sql = "SELECT * FROM province";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($array = mysql_fetch_array($result)) {
$itemName = $array['provincename'];
$itemcode = $array['provinceno']; ?>

<option value="<?php print($itemcode); ?>"><?=$itemName?>

$sqlt = "SELECT * FROM city
LEFT JOIN province ON city.provinceno = province.provinceno
WHERE `province`.`provinceno` = `city`.`provinceno` AND city.provinceno='$itemcode';

}  ?>
<select name="items2">
<option value="">Choose city</option>
$resultt = mysql_query($sqlt,$conn) or die(mysql_error());
while ($array = mysql_fetch_array($resultt)) {
$itemNamet = $array['cityname'];
$itemci = $array['provinceno'];

<option value="<?php print($itemci); ?>"><?=$itemNamet?>
}  ?>





User avatar
New php-forum User
New php-forum User
Posts: 25
Joined: Fri Sep 14, 2012 12:06 am

Re: relation two listbox

Postby TomCornar » Sun Sep 16, 2012 11:27 pm

On first select box the juery .ajax()
Use Jquery Post to php file and get the value from db.On success append the value to the selectbox.

hope this helps
Tom Cornar
Trinay Technology Solutions

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest