saikiran Posted July 10, 2006 Share Posted July 10, 2006 hi, First post in this forumi am using a drop down select menu to choose a particular category of products from my database table.I want to give one default option in the select menu, Select ALL, whenever user select this and press the submit button it should retrieve all the records.kindly check out the below given code and help me out.Dynamic select menu code[color=red]<?php include('config.php');?><? $query = "SELECT distinct product FROM prod_catlog2"; $result = mysql_query($query); $pulldown = '<option>Select one option</option>'; while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $pulldown .= "<option value = \"{$row['product']}\">{$row['product']}</option>\n"; }?> <html><title>Order Form</title><form action="show_ord_det_pg_org.php" method="POST">Select your category<select name="cat"><?php echo $pulldown;?> </select><br><input type="submit" name="submit" value="Show Details"></form></html>[/color][b]show_ord_det_pg_org.php[/b][color=red]...<?php $cat = $_POST['cat']; $sql = "select * from prod_catlog2 where product = '$cat'"; $result = mysql_query($sql)or die(mysql_errno().mysql_error());?> ....[/color]here $cat is the variable which stores the option that user will pick from the select menu, whose name is cat.kindly help me outcheerssaisaisen76@hotmail.com Link to comment https://forums.phpfreaks.com/topic/14150-working-with-select-menu-in-php/ Share on other sites More sharing options...
AV1611 Posted July 10, 2006 Share Posted July 10, 2006 <?php include('config.php');?><? $query = "SELECT distinct product FROM prod_catlog2"; $result = mysql_query($query); $pulldown = '<option>Select one option</option>'; $pulldown .= '<option>ALL</option>'; while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $pulldown .= "<option value = \"{$row['product']}\">{$row['product']}</option>\n"; }?> <html><title>Order Form</title><form action="show_ord_det_pg_org.php" method="POST">Select your category<select name="cat"><?php echo $pulldown;?> </select><input type="submit" name="submit" value="Show Details"></form></html><?php if($_POST['cat']=='ALL') {$cat='%';}else {$cat = $_POST['cat'];} $sql = "select * from prod_catlog2 where product like '$cat'"; $result = mysql_query($sql)or die(mysql_errno().mysql_error());?> Link to comment https://forums.phpfreaks.com/topic/14150-working-with-select-menu-in-php/#findComment-55444 Share on other sites More sharing options...
saikiran Posted July 10, 2006 Author Share Posted July 10, 2006 hi,Thank u AV1611. You have solved my problem. Thank you once again.cheerssaikiran Link to comment https://forums.phpfreaks.com/topic/14150-working-with-select-menu-in-php/#findComment-55462 Share on other sites More sharing options...
Recommended Posts