relation two listbox

General discussions related to php

Moderators: macek, egami, gesf

msasan1367
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

Hi
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
thanks

Code: Select all



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

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

</head>


<body>
<table>
<tr>
<td colspan=”2″>Religion</TD>
<td>
<select name="items">
<option value="">Choose province</option>
<?
$conn=mysql_connect("127.0.0.1", "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>
</td>
</tr>
<tr>
<td>
<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?>
<?
}  ?>
 

</select>

</td></tr>
</table>

</body>

</html>



User avatar
TomCornar
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 onchange.call 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
Regards,
Tom Cornar
Trinay Technology Solutions
http://www.trinay.com


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 3 guests