View Full Version : displaying records in a table of 3 cels in a row.
Red Blaze
11-30-2005, 12:21 PM
Here's my problem. I have a table and I dont want it to be any bigger than 3 cells a row. I have 5 records in a table in the database. How can I display 3 records per row? Thank you for the help.
Andrew
11-30-2005, 02:45 PM
You just need to limit the MySQL query like so:
SELECT column1,column2,column3 FROM table_name LIMIT 3
Red Blaze
11-30-2005, 03:09 PM
No no, I didn't explain myself correctly.
http://www.tdswebnet.com/webhosting2.php
I want all records to show, but 3 in a row. Not just 3 records. I tried what you posted, and that only showed 3 of the 5 records. Unless I did something wrong.
<table align="center">
<tr>
<?php do { ?>
<td><table width="300" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="name_gradient"><?php echo $row_callhosting['feature']; ?></td>
</tr>
<tr>
<td class="lite_blue">Starting At<br />
<span class="style2"><strong><?php echo $row_callhosting['price']; ?></strong></span><br />
<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('BuyNow','','images/buynow_over.jpg',1)"><br />
<img src="images/buynow_out.jpg" alt="Buy Now!" name="BuyNow" width="110" height="47" border="0" id="BuyNow" align="center"/></a><br /> </td>
<td class="feature_table"><span class="features">FEATURE</span><br />
Space: <?php echo $row_callhosting['space']; ?><br />
Bandwidth: <?php echo $row_callhosting['bandwidth']; ?><br />
Database(s): <?php echo $row_callhosting['db']; ?><br />
Email Accounts: <?php echo $row_callhosting['email']; ?><br />
FTP Accounts: <?php echo $row_callhosting['ftp']; ?><br />
Domains: <?php echo $row_callhosting['domains']; ?><br />
<?php echo $row_callhosting['scripts']; ?><br />
Cpanel: <?php echo $row_callhosting['cpanel']; ?></td>
</tr>
</table>
</td>
<?php } while ($row_callhosting = mysql_fetch_assoc($callhosting)); ?>
</tr>
</table>
That's the table.
Andrew
11-30-2005, 03:16 PM
Ah - See if this works:
<table align="center">
<tr>
<?php
// Variable to handle the number of columns
$newline = 0;
do {
?>
<td>
<table width="300" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" class="name_gradient"><?php echo $row_callhosting['feature']; ?></td>
</tr>
<tr>
<td class="lite_blue">Starting At<br />
<span class="style2"><strong><?php echo $row_callhosting['price']; ?></strong></span><br />
<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('BuyNow','','images/buynow_over.jpg',1)"><br />
<img src="images/buynow_out.jpg" alt="Buy Now!" name="BuyNow" width="110" height="47" border="0" id="BuyNow" align="center"/></a><br />
</td>
<td class="feature_table"><span class="features">FEATURE</span><br />
Space: <?php echo $row_callhosting['space']; ?><br />
Bandwidth: <?php echo $row_callhosting['bandwidth']; ?><br />
Database(s): <?php echo $row_callhosting['db']; ?><br />
Email Accounts: <?php echo $row_callhosting['email']; ?><br />
FTP Accounts: <?php echo $row_callhosting['ftp']; ?><br />
Domains: <?php echo $row_callhosting['domains']; ?><br />
<?php echo $row_callhosting['scripts']; ?><br />
Cpanel: <?php echo $row_callhosting['cpanel']; ?>
</td>
</tr>
</table>
</td>
<?php
// Increase the number of columns displayed
$newline++;
if ($newline == "3")
{
// Start a new row and reset the $newline variable
echo ("</tr><tr>\n");
$newline = 0;
}
} while ($row_callhosting = mysql_fetch_assoc($callhosting));
// Add any additional columns if needed to fill the last row
for ($newline; $newline < 3; $newline++)
{
echo ("<td> </td>\n");
}
?>
</tr>
</table>
Red Blaze
11-30-2005, 03:34 PM
Yes it did. I really appreciate your help. I'm going to have to study what it says so I can understand how it was done. Thank you so very much.
Andrew
11-30-2005, 03:37 PM
Your very welcome - I tried to comment my changes so you would understand it. Basically, I used a variable to see how many cells had been displayed so far. Then after each cell I do a check to see if three have been displayed yet. If so, then it starts a new row and the process starts over. At the end then, I used a for() loop to fill in any remaining cells, so that way the table would display properly. Feel free to PM me if you have any more PHP/MySQL questions and I'll be more than happy to help you out.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.