Jump to content

PHP Query Database into HTML Tables


cjbeck71081

Recommended Posts

Hello

I 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" button
2. query MySql DB find 11 table entries
3. Create 11 tables on the "listings" page and populate the table with variables

Thanks in advance
Chris
Link to comment
https://forums.phpfreaks.com/topic/28105-php-query-database-into-html-tables/
Share on other sites

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.