Forum Moderators: coopster

Message Too Old, No Replies

Drop Down box population, mysql query and Javascript

drop down box population with mysql query and javascript

         

xKillswitchx

6:06 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



I have run into something that is really starting to iritate me. I am writing a small application (small CMS) where I can add content into sections and categories.

I first add a section, then a category to that section, then add my content item inside the category. It creates a good structure for my site / URLs.

Anyways, I have everything designed, except I have drop down to allow me to choose my section and category on the add content page. When I choose a section, I want the category drop down to adjust to show only the categories inside that section. I have found javascript that does this, but how do I integrate the PHP into this? I think it would mainly be simple queries (SELECT id, name FROM sec_table WHERE section_id = '" .$cat->catid. "' or something similar (thats not the real query, just a really quick example.

Any ideas on how to do this? I would link to the javascript, but I dont think I am allowed to here.

javascript(.)internet.com/forms/dropdown-box-population.html

Any help is greatly appreciated, this is really slowing me down and driving me crazy.

d40sithui

6:32 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



this is one way to do it. although its better if you integrate it with ajax.
anyway, lets say you have this script.

/////index.php
<script>
function reload(form){
var subcat= form1.cat.options[form1.cat.options.selectedIndex].value;
self.location = 'index.php?subcat='+subcat;

}
</script>

<form name="form1">
<select name="cat" onchange="reload(this.form);">
<option value='1'>
<option value='2'>
<option value='3'>
</select>
</form>

<?
if(isset($_REQUEST['subcat'])){
//display your sub category select form here
$query = "select * from some_table where subcat=".$_REQUEST['subcat'];
//dont forget to filter out bad strings!

}

?>

hopefully this will give you an idea, although im sure there are other ways to do it.

xKillswitchx

6:42 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Thanks a million. I will play around with this and see what I can come up with.

I have been looking at working more with AJAX (I don't know Javascript, but have been checking it out. Seems alot like PHP, with slightly more to it). I have been looking at Sarissa for AJAX, seems easy enough to integrate adn cross browser compatible.