Note that there are some explanatory texts on larger screens.

plurals
  1. POajax get dropdown dependent values
    primarykey
    data
    text
    <p>I am just a newbie in <code>php,jquery and ajax</code>.I want to fetch the <code>state and city name</code> from the <code>country name</code> from database. I have my database is something like this</p> <pre><code>CREATE TABLE IF NOT EXISTS `propertylocator` ( `store_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `store_name` varchar(255) NOT NULL, `country_name` varchar(255) NOT NULL, `state_name` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL, `address` varchar(255) NOT NULL, `description` varchar(255) NOT NULL PRIMARY KEY (`store_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; INSERT INTO `propertylocator` (`store_id`, `store_name`, `country_name`, `state_name`, `city_name`, `address`, `description`) VALUES (1, 'My property1', 'India', 'uttar pradesh', 'Ghaziabad', 'Pilkhuwa, Uttar Pradesh 245304, India', 'this is demo test','this is dummy description'), (2, 'My new Property', 'India', 'Maharashtra', 'Thane', 'Kudavali, Maharashtra 421401, India', 'test propery again', 'another dummy property'), (3, 'Dummy store', 'United Arab Emirates', 'Sharjah', 'Halwan Suburb', 'Al Ghubaiba - Sharjah - United Arab Emirates', 'this is another dummy store','another text with dummy'); </code></pre> <p>Now here I have 3 drop downs one for <code>country name</code>, 2nd for <code>state name</code> and another for <code>city name</code>. In <code>countryname dropdown</code> I am getting all the <code>countryname</code>. But I want that when I will select <code>country name(lets say india here)</code> then I will get the dropdown options for state will be <code>uttar pradesh and Maharashtra</code> as they both have the countryname is india, and when I will select United Arab Emirates from country list then I will get all the states name whose country name is<code>United Arab Emirates in the database</code>. In the same way it will applied for the <code>cityname</code>. For all this stuff I have done <code>jQuery ajax</code> like this</p> <pre><code>&lt;label&gt;Please Select Country&lt;/label&gt;&lt;/td&gt;&lt;td&gt; &lt;div class="country"&gt; &lt;select id="country" name="country" onchange="selectCountry();"&gt; &lt;option value="Select"&gt;Select&lt;/option&gt; foreach($countrylist as $country) { &lt;option value="$country['country_name]" id="$country['country_name]"&gt;echo $country['country_name]&lt;/option&gt; } &lt;/select&gt; </code></pre> <p>and in function <code>selectCountry()</code> my code is like this</p> <pre><code>function selectCountry() { var state = $('#country').val(); console.log(state); $.ajax({ type: "GET", url: "selectstate.php", data: { sta : state } }).done(function(html) { $('#state').html(html); }) } </code></pre> <p>in selectstate.php I have my query like this</p> <pre><code>mysql_connect('localhost','root','') or die(mysql_error()); mysql_select_db(propertylocator) or die(mysql_error()); $sDB = new SelectDb(); $data = $sDB-&gt;selectStatesById($_GET['sta']); foreach($data as $row) { echo "&lt;option value=" . $row-&gt;state . "&gt;" . $row-&gt;name . "&lt;/option&gt;"; } </code></pre> <p>But here I am not getting any results. It is showing 404 not found error. So can someone kindly tell me whats the issue here.</p> <p>If there is some error in my code then kindly solve it. So that I can understand the code properly. Thanks</p> <p><strong>Update</strong> I have checked the url path and made it more clearly so one can track the problem.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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