gateway69 Posted January 26, 2007 Share Posted January 26, 2007 Im trying to write a function that pulls data from 2 tables in a database.categories and subcategories which has a pointer to categories so you know sub is linked to which category.[code]<?php/// List categories for add video pull down category menusfunction viewcategories($userlevel){ global $database; $q = "SELECT categories.id,categories.name,subcategories.id,subcategories.name from categories,subcategories WHERE subcategories.catid = categories.id and categories.active ='1' and categories.disable='1' and subcategories.active ='1' and subcategories.disable='1' ORDER by categories.id"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<label>Category:<br />\n"; echo "<select>"; for($i=0; $i<$num_rows; $i++){ $rows = mysql_fetch_array($result); echo "<option value=".$rows[0].">".$rows[1]."</option>\n"; } echo "</select>\n"; echo "</lable><br><br>\n"; // list subcatories in the forum // echo "<label>Subcatory<br />\n"; // echo "<option value='$id'>$name</option>"; // echo "</lable>";}?>[/code]this is what I have so fare, and this function is called on another page, where the rest of the form is located.currently this prints out the categories in a pulldown menu.$row[0] = id value in the database for category table$row[1] = name value in the database for category table$row[2] = id value in the database for subcategory table$row[3] = name value in the database for subcategory tableim pretty much stuck here, I can populate the pulldown menu for category but not sure how to do the subcategory and also change the values when the user selects a different category , and repopulate the subcategory based upon changes.im assuming this needs a bit of javascript.Any advice on how I should proceed.?steve Quote Link to comment Share on other sites More sharing options...
jumpenjuhosaphat Posted January 26, 2007 Share Posted January 26, 2007 Yes, to change the contents of a drop down menu without reloading the page, you would have to use javascript. You could populate the drop down by indenting each subcategory....Category 1 -->subcategory 1 -->subcategory 2 -->subcategory 3Category 2 -->subcategory 1 -->etc......That way you would only have to populate the drop down once, and you wouldn't have to worry about using any js. Quote Link to comment Share on other sites More sharing options...
gateway69 Posted January 26, 2007 Author Share Posted January 26, 2007 im not sure i understand what you mean by indenting, i know what indent means, but in the context of code what do you mean can you give me an example? Quote Link to comment Share on other sites More sharing options...
gateway69 Posted January 26, 2007 Author Share Posted January 26, 2007 never mind on the indent, i hadnt had my coffee yet, anyone point me to some way to work with PHP and JS for pulldown menus, I would like to expand my skills a bit and im sure Ill have to use this method at some point. Steve[url=http://ibareitall.com]I Bare It All Blog[/url] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Check out the mootools framework - mootools.net Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.