cjbeck71081 Posted November 22, 2006 Share Posted November 22, 2006 HelloI have used this forum a few times before and apprecaite everyones help. I have learned alot about PHP but i have come across a problem that im unfamiliar with. It should be simple, im just not sure the context to use.I have a client that wants to put together a page that shows Listings of houses for sale. I want to pass the information through a PHP Query and on the next page have a table that shows the house picture, and stats about the house. If the number of houses that would be on the page was a fixed number, that would be easy. However im assuming that the number of houses he wants to show on that page will vary. So i think the first thing that the Query needs to do is run a loop so it knows how many houses are on the page, so it can then create the number of tables required to show the number houses correctly.For example.... 1. click "listings" button2. query MySql DB find 11 table entries3. Create 11 tables on the "listings" page and populate the table with variablesThanks in advanceChris Link to comment https://forums.phpfreaks.com/topic/28105-php-query-database-into-html-tables/ Share on other sites More sharing options...
Psycho Posted November 22, 2006 Share Posted November 22, 2006 You just need to put the logic for building the table within a loop, or alternatively you could make it a function and call it for each record.Example of the logic[code]<?php$result = mysql_query("SELECT * FROM houses WHERE this = 'that'"); while ($row = mysql_fetch_array($result)) { echo "<table>"; echo "<tr>"; echo "<td>".$row[propertyname]."</td>"; echo "<td>".$row[rooms]."</td>"; echo "<td>".$row[bathrooms]."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><img src=\"".$row[picture]."\"></td>"; echo "<td>".$row[sqfeet]."</td>"; echo "<td>".$row[price]."</td>"; echo "</tr>"; echo "<table></br>"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/28105-php-query-database-into-html-tables/#findComment-128630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.