shure2 Posted April 7, 2010 Share Posted April 7, 2010 Hi, I have a list box that reads category names from the category table. I want to select a category name and populate the product list box with the names of products in the category. I have the code to populate the category listbox and the sql to populate the product listbox, but i'm not sure how to put them together (I guess calling a seperate php file and then passing the values back somehow using a form? - probably wrong!) CODE FOR SELECTING PRODUCT CATEGORY: <p>Select the product category:<br /> <select name="prodcategory" onchange="javascript: form.action='reportmanual_getcategoryproducts.php';"> <?php $selectProductCatQuery = "SELECT * FROM category where userid = '".$_SESSION['userid']."' ORDER BY catname"; $selectProductCatResult = mysql_query($selectProductCatQuery) or die(mysql_error()); while($row1ProductCat=mysql_fetch_array($selectProductCatResult)) { echo '<option value="'.$row1ProductCat['catname'].'">'.$row1ProductCat['catname'].'</option>'; } ?> </select> CODE FOR SELECTING PRODUCT (need help on this bit please): $query = "SELECT * FROM product where userid = '".$_SESSION['userid']."' and categoryname = '".$_GET['prodcategory']."' ORDER BY $result = mysql_query($query) or die(mysql_error()); //I need to get the values from the sql and pass them back to the product select box i have Link to comment https://forums.phpfreaks.com/topic/197838-how-can-i-populate-one-list-box-from-the-selection-of-another-list-box/ Share on other sites More sharing options...
shure2 Posted April 7, 2010 Author Share Posted April 7, 2010 I have created a listbox that populates the product names on a seperate page (seen below), but I want the two list boxes to be on the same page, I don't mind if the page refreshes when the category is selected (to avoid javascript) $query = "select * from product where prodcategory = '".$_GET['prodcategory']."' and userid = '".$_SESSION['userid']."'"; $result = @mysql_query($query, $connection)or die ("Unable to perform query<br>$query"); ?> <select name="dddd"> <?php while($row=mysql_fetch_array($result)) { echo '<option value="'.$row['prodid'].'">'.$row['prodname'].'</option>'; echo 'hello'; } //exit(); ?> </select> Link to comment https://forums.phpfreaks.com/topic/197838-how-can-i-populate-one-list-box-from-the-selection-of-another-list-box/#findComment-1038200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.