PHP Table Repeat

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
carboncopy420
Forum Newbie
Posts: 3
Joined: Sat Mar 17, 2007 9:47 am

PHP Table Repeat

Post by carboncopy420 »

Hi Guys,

I want to take information from an SQL database and have it displayed in a table. I don't want the table to look like a spreadsheet i want each item to have it's own table. I was able to make one table and connect it to the database so it would display the information but I can't get it to repeat until there are no entries left. It is a very simple database with all the information displayed in one table, there is no need to have more tables connected to it. I just want it to display the information. Any Ideas?

Thanks,
CarbonCopy420
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code?
carboncopy420
Forum Newbie
Posts: 3
Joined: Sat Mar 17, 2007 9:47 am

Code

Post by carboncopy420 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Sorry... Here is the code that displays the table and all the information I want..The only problem is that it will only display the first record... I just need it to repeat the table for all the records.

Thanks
CarbonCopy420

Code: Select all

<?php require_once('Connections/BJData.php'); ?>
<?php
mysql_select_db($database_BJData, $BJData);
$query_BJDATA = "SELECT * FROM TruckEntry";
$BJDATA = mysql_query($query_BJDATA, $BJData) or die(mysql_error());
$row_BJDATA = mysql_fetch_assoc($BJDATA);
$totalRows_BJDATA = mysql_num_rows($BJDATA);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
&nbsp;
<hr>
<table border="0" width="100%" height="278" id="table29">
  <tr>
    <td width="50%" colspan="2" height="41"><p align="center"><?php echo $row_BJDATA['Year']; ?></td>
    <td width="25%" height="41"><p align="center"><?php echo $row_BJDATA['Make']; ?><font size="5"> </font></td>
    <td width="23%" height="41" colspan="2"><p align="center"><?php echo $row_BJDATA['Model']; ?><span style="background-color: #FFFFFF"> </span></td>
  </tr>
  <tr>
    <td width="32%" rowspan="9">&nbsp;</td>
    <td width="18%" rowspan="4" height="0">&nbsp;</td>
    <td align="center" height="22"><span style="background-color: #FFFFFF">Engine</span></td>
    <td height="22" colspan="2"><span style="background-color: #FFFFFF">&nbsp;<?php echo $row_BJDATA['Engine']; ?></span></td>
  </tr>
  <tr>
    <td align="center"><span style="background-color: #FFFFFF"> Transmission</span></td>
    <td colspan="2"><?php echo $row_BJDATA['Transmission']; ?></td>
  </tr>
  <tr>
    <td align="center" height="24"><span style="background-color: #FFFFFF">Mileage</span></td>
    <td height="24" width="11%"><?php echo $row_BJDATA['Mileage']; ?></td>
    <td height="24">KM</td>
  </tr>
  <tr>
    <td align="center" height="21"><span style="background-color: #FFFFFF">Front Axle</span></td>
    <td height="21" colspan="2"><?php echo $row_BJDATA['Front_Axel']; ?></td>
  </tr>
  <tr>
    <td width="18%" rowspan="5"><p align="center"><a href="mailto:sales@bjtrucks.pe.ca"> <span style="background-color: #FFFFFF"> <img border="0" src="file:///C|/Documents and Settings/Nicholas/Application Data/Macromedia/Dreamweaver MX 2004/OfficeImageTemp/email.gif" width="40" height="40"></span></a><span style="background-color: #FFFFFF"><br>
        E-Mail for More<br>
        Information</span></td>
    <td align="center"><span style="background-color: #FFFFFF"> Rear Axle</span></td>
    <td colspan="2"><?php echo $row_BJDATA['Rear_Axel']; ?></td>
  </tr>
  <tr>
    <td align="center"><span style="background-color: #FFFFFF"> Ratio</span></td>
    <td colspan="2"><?php echo $row_BJDATA['Ratio']; ?></td>
  </tr>
  <tr>
    <td align="center">Wheel Base</td>
    <td colspan="2"><?php echo $row_BJDATA['Wheel_Base']; ?></td>
  </tr>
  <tr>
    <td align="center">Dump</td>
    <td colspan="2"><?php echo $row_BJDATA['Dump']; ?></td>
  </tr>
  <tr>
    <td align="center">Price</td>
    <td colspan="2"><?php echo $row_BJDATA['Price']; ?></td>
  </tr>
</table>
<table border="0" width="100%" id="table30">
  <tr>
    <td><font size="4"><b><span style="background-color: #FFFFFF"> Description: <?php echo $row_BJDATA['Description']; ?></span> </b></font></td>
  </tr>
</table>
<div id="_wfx_document28">
  <div id="container28">
    <div id="main_container28"> &nbsp;
        <hr>
        <div id="_wfx_document29">
          <div id="container29">
            <div id="main_container29">
              <p align="center"> </div>
          </div>
        </div>
    </div>
  </div>
</div>

</body>
</html>
<?php
mysql_free_result($BJDATA);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing a loop to fetch more records.
carboncopy420
Forum Newbie
Posts: 3
Joined: Sat Mar 17, 2007 9:47 am

Post by carboncopy420 »

Any idea what loop code I would use? I am very new at PHP.

CarbonCopy420
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A typical fetch loop looks like

Code: Select all

while($row = mysql_fetch_assoc($resultSet))
{
  // do stuff with result data
}
Post Reply