frank_solo Posted March 8, 2011 Share Posted March 8, 2011 I'm new to this forum and I would like to thank everyone in advance for the help. I've got a drop down menu where someone can make the selection and I need it to display in a table using HTML_Table, but all I get is the headers. I'm providing the code down below can someone please help me? Thanks. <?php if ($_POST){ $county = $_POST['county']; $rooms = $_POST['type']; $rent = $_POST['rent']; $rent_min = $rent - 500; } $dbase = mysql_connect ( 'localhost', ' ', ' ' ); mysql_select_db ( ' ', $dbase ); if($county){ $sql = "SELECT * FROM `apartments` WHERE `county` = '".$county."' AND `rooms` = '".$rooms."' AND `rent` < '".$rent."' AND `rent` > '".$rent_min."' "; }else{ $sql = "SELECT * FROM `apartments`"; } $res = mysql_query($sql, $dbase); require_once 'HTML/Table.php'; $attrs = array('width' => '600'); $table = new HTML_Table(); $table->setAttributes($attrs); for ($nr = 0; $nr < count($data); $nr++) { $table->setHeaderContents($nr+1, 0, (string)$nr); for ($i = 0; $i < 4; $i++) { if ('' != $data[$nr][$i]) { $table->setCellContents($nr+1, $i+1, $data[$nr][$i]); } } } $altRow = array('bgcolor' => '#999969'); $table->altRowAttributes(1, null, $altRow); // Create the table object $table = new HTML_Table(); // Set the headers $table->setHeaderContents(0, 0, "County"); $table->setHeaderContents(0, 1, "Town"); $table->setHeaderContents(0, 2, "Phone"); $table->setHeaderContents(0, 3, "Rooms"); $table->setHeaderContents(0, 4, "Bath"); $table->setHeaderContents(0, 5, "Rent"); $hrAttrs = array('bgcolor' => '#333333'); $table->setRowAttributes(0, $hrAttrs, true); $table->setColAttributes(0, $hrAttrs); $rownum = 1; // don't overwrite header of table while($row = mysql_fetch_assoc($res)) $table->altRowAttributes(1, null, array("class"=>"alt")); // Output the data echo $table->toHtml(); Quote Link to comment https://forums.phpfreaks.com/topic/229978-help-with-using-html_table/ Share on other sites More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 You're using $data in your for loop, but not setting it anywhere. Do you meant to use $res? Quote Link to comment https://forums.phpfreaks.com/topic/229978-help-with-using-html_table/#findComment-1184479 Share on other sites More sharing options...
frank_solo Posted March 8, 2011 Author Share Posted March 8, 2011 I've noticed that, thanks. I've changed the $data to $res but I still get the same result. Quote Link to comment https://forums.phpfreaks.com/topic/229978-help-with-using-html_table/#findComment-1184489 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.