0

I have did some code but now i want to add sub categories in my main category but now i want when admin click on any option the page will automatically refresh because below this i have a sub category option when it will refresh the page then my particular subcategories will appear i hope if you guys have any suggestion then please suggest me.

<select name="cat">
                <option value='null'>Select your Desire</option>
                <?php
                include('includes/db.php');
                $c_query="select * from categories";
                $c_run=(mysql_query($c_query));
                while($c_row=mysql_fetch_array($c_run)){
                    $c_id=$c_row['p_id'];
                    $c_title=$c_row['p_title'];
                    echo "<option value='$c_id'>$c_title</option>";
                    }
                ?>
            </select>
  • $(function() { $('select[name="cat"]').change(function() { location.href = 'page.php?cat=' + $(this).find('option:selected').val(); }); }); – LS11 Nov 13 '14 at 17:24
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). You will also want to [Prevent SQL Injection!](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Nov 13 '14 at 17:26
  • can you please edit my code then i'll understand easily plz if you want to do..plz – user3774870 Nov 13 '14 at 17:39
  • Why don't you try ajax to load second dropdown list, instead of refreshing page? – Apul Gupta Nov 13 '14 at 18:21

1 Answers1

0

Instead of submitting the page on change of first dropdown, use Ajax to get options for second dropdown list.

Read this tutorial: http://www.plus2net.com/php_tutorial/ajax_drop_down_list.php

Apul Gupta
  • 3,044
  • 3
  • 22
  • 30