cluce Posted September 12, 2007 Share Posted September 12, 2007 I am trying to display all and selected data based on an IF condition. It will either execute all the data from the table or selected data based on category. well at least it is supposed too. I can take out the select * query and it will work but I need to use both. And I want the page to load all the data from the table on reload or load and when someone selects the list box and hits submit it will only display the selected ones on a web page. Its probably something simple but I cant see why I dont get any results to display. need help on this <!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> <script type='text/javascript' src='common.js'></script> <script type='text/javascript' src='css.js'></script> <script type='text/javascript' src='standardista-table-sorting.js'></script> </head> <body> <?php //connect to database include'db.php5'; if (isset($_POST['submit'])){ //get selected data of records $get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'"; $result = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli)); }else{ //get all data from table $sql = "SELECT * from products"; $result = mysqli_query($mysqli, $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>"; } ?> <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> <p> <input type="submit" name="submit" value="Submit" > </p> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 12, 2007 Share Posted September 12, 2007 Add this to the top of your pages: ini_set('display_errors', 1); error_reporting(E_ALL); This one and the db one Quote Link to comment Share on other sites More sharing options...
cluce Posted September 12, 2007 Author Share Posted September 12, 2007 Add this to the top of your pages: ini_set('display_errors', 1); error_reporting(E_ALL); This one and the db one my errors are turned on. the whole page isnt blank just the part where the data needs to be displayed. I still get the list box and text to display. Quote Link to comment Share on other sites More sharing options...
cluce Posted September 12, 2007 Author Share Posted September 12, 2007 well i know why it didnt display but no I get this error" Notice: Undefined variable: display_block in C:\www\vhosts\reagan\sqllistbox.php on line 69" the problem before I had to <?php echo($display_block); ?> I guess its in the wrong place?? But i am not sure where to put it? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 12, 2007 Share Posted September 12, 2007 Well thats not what you said before. I don't see where you print that variable, but you need to print it only if it's already defined. Quote Link to comment Share on other sites More sharing options...
cluce Posted September 12, 2007 Author Share Posted September 12, 2007 Well thats not what you said before. I don't see where you print that variable, but you need to print it only if it's already defined. I know my mistake. here is my code. can you maybe see where its causing the error Notice: Undefined variable: display_block in C:\www\vhosts\reagan\sqllistbox.php on line 69" <!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> <script type='text/javascript' src='common.js'></script> <script type='text/javascript' src='css.js'></script> <script type='text/javascript' src='standardista-table-sorting.js'></script> </head> <body> <?php //connect to database include'db.php5'; if (!isset($_POST['submit'])){ //get all data from table $sql = "SELECT * from products"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); }else{ //get selected data of records $get_list_sql = "SELECT * FROM products WHERE Category = '".$_POST['select']."'"; $result = 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>"; } echo ($display_block); ?> <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> <p> <input type="submit" name="submit" value="Submit" > </p> Quote Link to comment Share on other sites More sharing options...
cluce Posted September 12, 2007 Author Share Posted September 12, 2007 my code half way works when I make this change... if (isset($_POST['submit'])){ delete this //get all data from table delete this //$sql = "SELECT * from products"; delete this//$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //}else{ but it only displays the selected data not all the data on page load or reload . I am trying to get it to do both??? Quote Link to comment Share on other sites More sharing options...
cluce Posted September 12, 2007 Author Share Posted September 12, 2007 topic solved. I had my brakets in the wrong place. thanks for you time 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.