Note that there are some explanatory texts on larger screens.

plurals
  1. POphp mysql + ajax and jquery to dpopulate dynamic drop list
    primarykey
    data
    text
    <p>i am creating 2 dynamic drop list that the second one is based on the selection of the first but the problem is that the second one do not populate and i do not know where is the error can anyone help me ????</p> <h1>dbconfig.php</h1> <pre><code>&lt;?php $host = "localhost"; $user = "*****"; $password = "****"; $db = "lam_el_chamel_db"; ?&gt; </code></pre> <h1>select.php</h1> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $("select#district").attr("disabled","disabled"); $("select#governorate").change(function(){ $("select#district").attr("disabled","disabled"); $("select#district").html("&lt;option&gt;wait...&lt;/option&gt;"); var id = $("select#governorate option:selected").attr('value'); $.post("select_district.php", {id:id}, function(data){ $("select#district").removeAttr("disabled"); $("select#district").html(data); }); }); $("form#select_form").submit(function(){ var cat = $("select#governorate option:selected").attr('value'); var type = $("select#district option:selected").attr('value'); if(cat&gt;0 &amp;&amp; type&gt;0) { var result = $("select#district option:selected").html(); $("#result").html('your choice: '+result); } else { $("#result").html("you must choose two options!"); } return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php include "select.class.php"; ?&gt; &lt;form id="select_form"&gt; Choose a governorate:&lt;br /&gt; &lt;select id="governorate"&gt; &lt;?php echo $opt-&gt;ShowGovernorate(); ?&gt; &lt;/select&gt; &lt;br /&gt;&lt;br /&gt; choose a district:&lt;br /&gt; &lt;select id="type"&gt; &lt;option value="0"&gt;choose...&lt;/option&gt; &lt;/select&gt; &lt;br /&gt;&lt;br /&gt; &lt;input type="submit" value="confirm" /&gt; &lt;/form&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h1>select class.php</h1> <pre><code>&lt;?php class SelectList { protected $conn; public function __construct() { $this-&gt;DbConnect(); } protected function DbConnect() { include "dbconfig.php"; $this-&gt;conn = mysql_connect($host,$user,$password) OR die("Unable to connect to the database"); mysql_select_db($db,$this-&gt;conn) OR die("can not select the database $db"); return TRUE; } public function ShowGovernorate() { $sql = "SELECT * FROM governorate"; $res = mysql_query($sql,$this-&gt;conn); $governorate = '&lt;option value="0"&gt;choose...&lt;/option&gt;'; while($row = mysql_fetch_array($res)) { $governorate .= '&lt;option value="' . $row['governorate_id'] . '"&gt;' . $row['governorate_name'] . '&lt;/option&gt;'; } return $governorate; } public function ShowDistrict() { $sql = "SELECT * FROM districts WHERE governorate_id=$_POST[id]"; $res = mysql_query($sql,$this-&gt;conn); $district = '&lt;option value="0"&gt;choose...&lt;/option&gt;'; while($row = mysql_fetch_array($res)) { $district .= '&lt;option value="' . $row['district_id'] . '"&gt;' . $row['district_name'] . '&lt;/option&gt;'; } return $district; } } $opt = new SelectList(); ?&gt; </code></pre> <h1>select _type.php</h1> <pre><code>&lt;?php include "select.class.php"; echo $opt-&gt;ShowDistrict(); ?&gt; </code></pre> <h1>table structure</h1> <p>governorate : </p> <ul> <li>governorate_id</li> <li>governorate_name</li> </ul> <p>districts:</p> <ul> <li>district_id,</li> <li>district_name,</li> <li>governorate_id.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload