cluce Posted September 11, 2007 Share Posted September 11, 2007 I am not sure how to display data on a web page in a table based on selection in a list box. I am just not sure how to execute the onclick beahvior from the list box to do this? I tried googling for an example on the web but I cant find anything that will help me code this?? can someone look at my code of what I have so far? ??? Any feedback is appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php //connect to database include'db.php5'; //get parts of records $get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'"; $get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli)); //create table with the selected data $display_block = "<p align = 'center'> <table class='sortable' border = '1' bordercolor = 'black' cellpadding= '0' cellspacing = '0'> <thead> <th bgcolor = 'orange'>Item Number</th> <th bgcolor = 'orange'>Manufacturer</th> <th bgcolor = 'orange'>Category</th> <th bgcolor = 'orange'>Description</th> <th bgcolor = 'orange'>Model</th> <th bgcolor = 'orange'>Quantity</th> <th bgcolor = 'orange'>Kw</th> <th bgcolor = 'orange'>Hours</th> <th bgcolor = 'orange'>Price</th> </thead>"; //if authorized, get the values while ($info = mysqli_fetch_array($result)) { $ItemNo = stripslashes($info['Item_No']); $Man = stripslashes($info['Manufacturer']); $Cat = stripslashes($info['Category']); $Des = stripslashes($info['Description']); $Model = stripslashes($info['Model']); $Qty = stripslashes($info['Qty']); $Kw = stripslashes($info['Kw']); $Hours = stripslashes($info['Hours']); $Price = stripslashes($info['Price']); //create display string $display_block .= " <tr> <td class = 'numeric'>".$ItemNo."</td> <td>".$Man."</td> <td>".$Cat."</td> <td>".$Des."</td> <td>".$Model."</td> <td>".$Qty."</td> <td>".$Kw."</td> <td>".$Hours."</td> <td>".$Price."</td> </tr>"; } $display_block .= "</table></p>"; //display selected data in a table //free result mysqli_free_result($get_list_res); ?> <form id="form1" name="form1" method="post" action=""> <label> <div align="right">Display by Category: <select name="select"> <option>Diesal</option> <option>Engines</option> <option>Generators</option> </select> </div> </label> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/68860-solved-not-sure-how-to-display-data-on-a-web-page-based-on-selection-in-a-list-box/ Share on other sites More sharing options...
pocobueno1388 Posted September 11, 2007 Share Posted September 11, 2007 Well, you need a submit button to submit the form...see if this gets you what you want. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if (isset($_POST['submit'])){ //connect to database include'db.php5'; //get parts of records $get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'"; $get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli)); //create table with the selected data $display_block = "<p align = 'center'> <table class='sortable' border = '1' bordercolor = 'black' cellpadding= '0' cellspacing = '0'> <thead> <th bgcolor = 'orange'>Item Number</th> <th bgcolor = 'orange'>Manufacturer</th> <th bgcolor = 'orange'>Category</th> <th bgcolor = 'orange'>Description</th> <th bgcolor = 'orange'>Model</th> <th bgcolor = 'orange'>Quantity</th> <th bgcolor = 'orange'>Kw</th> <th bgcolor = 'orange'>Hours</th> <th bgcolor = 'orange'>Price</th> </thead>"; //if authorized, get the values while ($info = mysqli_fetch_array($result)) { $ItemNo = stripslashes($info['Item_No']); $Man = stripslashes($info['Manufacturer']); $Cat = stripslashes($info['Category']); $Des = stripslashes($info['Description']); $Model = stripslashes($info['Model']); $Qty = stripslashes($info['Qty']); $Kw = stripslashes($info['Kw']); $Hours = stripslashes($info['Hours']); $Price = stripslashes($info['Price']); //create display string $display_block .= " <tr> <td class = 'numeric'>".$ItemNo."</td> <td>".$Man."</td> <td>".$Cat."</td> <td>".$Des."</td> <td>".$Model."</td> <td>".$Qty."</td> <td>".$Kw."</td> <td>".$Hours."</td> <td>".$Price."</td> </tr>"; } $display_block .= "</table></p>"; //display selected data in a table //free result mysqli_free_result($get_list_res); } ?> <form id="form1" name="form1" method="post" action=""> <label> <div align="right">Display by Category: <select name="select"> <option>Diesal</option> <option>Engines</option> <option>Generators</option> </select> </div> </label> <input type="submit" name="submit" value="Submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/68860-solved-not-sure-how-to-display-data-on-a-web-page-based-on-selection-in-a-list-box/#findComment-346105 Share on other sites More sharing options...
cluce Posted September 11, 2007 Author Share Posted September 11, 2007 thats right. I guess I was thinking of when it gets selected in the list box it populates. but that functionality is done with javascript which I am not familiar with to well but this does work. thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/68860-solved-not-sure-how-to-display-data-on-a-web-page-based-on-selection-in-a-list-box/#findComment-346119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.