dynamically option selector


Dear All:

Anybody could advices me on this.

On my page, there are 2 option selector. 1 for category and 1 for subcategory.

The category option selector coding as below:


<?php include("list_var.php"); $db = mysql_connect($server,$dbuser,$dbpasswd); mysql_select_db($dbname); $sqlcat; $sqlsub; $result = mysql_query($sqlcat); if (!$result) { echo "Could not successfully run query ($sqlcat) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo ""; echo $row["category"]; echo ""; } mysql_free_result($result); echo ""; echo "
"; [/php] [b] What i want is, when user change the category code on the option selector. It will dynamically retrieve subcategory belong to the select category [/b] The tables structure to capture the category, subcategory and catedory_subcategory table as belows: [b]category:[/b] id category description [b]subcategory[/b] id subcategory description [b]maincat_subcat[/b] category subcategory Thanks

The only way to do this with PHP (directly) is to have it RE-submit the page and have it re-presented. PHP only presents STATIC pages in a dynamic way.

Sounds like wha tyou want to do will involve Javascript and that is what I would investigate.


Paul is correct on this. Javascript has is fully capable of handeling this. As I have done something similar to this with it before.


Thanks for advices.

Could you provide me some sample of script how you did it. or my references side i can refer to.

Thank a lot…


I would just search google for Javascript tutorials. Also, before you get far along, I would just like to mention that Javascript isn’t always the greatest way to go about doing something that is critical to a sites operation. Simply for the fact that Javascript can be turned off on the client side and if that is done then you site becomes useless to them.

Just something to think about.