Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 08-04-2009, 02:50 AM
gilbertsavier gilbertsavier is offline
Junior Member
 
Join Date: 06-29-09
Posts: 19
iTrader: 0 / 0%
PHP loop through database and limit number of entries

Hi,
Going to try to explain this as best I can. I have a bunch of stuff in a database and I need to display this info within a table. This isn't a problem at all but, I need it to only display 3 td tags per line and then move on to the row.

so i need it to do :

code:

<table>
<tr>
<td>My First Row</td>
<td>My First Row 2</td>
<td>My First Row 3</td>
</tr>

<tr>
<td>My Second Row</td>
<td>My Second Row 2</td>
<td>My Second Row 3</td>
</tr>
</table>



and continue to do this through every entry in the database table.

so I have something like this that will display the info:

code:

for ($i = 1; $i <= $num; $i++){

$chairArray = mysql_fetch_array($chairResult);
$chairName = $chairArray['name'];
$chairDescription = $chairArray['description'];
$chairImage = $chairArray['image'];

echo "<tr>";
echo "<td>";
echo "<img src=\"images/catalog/ottomans/thumbs/$chairImage\" width=\"157\" height=\"147\" />";
echo "<br />";
echo $chairName;
echo "</td>";
echo "</tr>";


}
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 08-04-2009, 07:23 AM
Izzmo's Avatar
Izzmo Izzmo is offline
v7n Mentor
 
Join Date: 11-01-03
Location: Kansas
Posts: 1,356
iTrader: 1 / 100%
This isn't the best way to do it.. but it would probably work...

Did you even need help on this, or is this an article?
 
Reply With Quote
  #3  
Old 08-05-2009, 03:51 PM
kieransimkin kieransimkin is offline
Contributing Member
 
Join Date: 06-25-09
Location: Brighton, UK
Posts: 116
iTrader: 0 / 0%
Try something a bit like this (I'll leave fixing the bugs to you):
Code:
$c=0; while ($row=mysql_fetch_assoc($chairResult)) { ++$c; if ($c % 3 == 0) { ?></tr><tr><?php } echo "<td>"; echo "<img src=\"http://www.v7n.com/forums/images/catalog/ottomans/thumbs/$chairImage\" width=\"157\" height=\"147\" />"; echo "<br />"; echo $chairName; echo "</td>"; }

Last edited by kieransimkin; 08-05-2009 at 03:52 PM. Reason: Add code tags
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP loop through database and limit number of entries gilbertsavier Coding Forum 2 07-14-2009 03:35 PM
How to retrieve the total number of rows when using LIMIT X, XXX yangyang Coding Forum 3 09-21-2008 06:27 PM
Number 1 baby, number 1, whoooooooooo! Simon - 1977 Google Forum 4 05-08-2004 02:23 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 01:23 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC