Limiting HTML Rows From An Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Limiting HTML Rows From An Query

Post by icesolid »

I have a table setup, now I want to pull a query from a MySQL database and put in 4 columns, and then then make a new row in HTML and enter in the next 4 columns of data, and have it a repeating process.

How do I go about doing so?
calebsg
Forum Commoner
Posts: 28
Joined: Tue Jun 18, 2002 10:41 am

Post by calebsg »

Code: Select all

<table>
<?$my_query = "SELECT * FROM table" or die ("error in query");
$my_result = mysql_query($my_query) or die ("error in result");
while ($my_row = mysql_fetch_array($my_result)) &#123;
echo "<tr><td>$my_row&#1111;"column_1"]</td><td>$my_row&#1111;"column_2"]</td><td>$my_row&#1111;"column_3"]</td><td>$my_row&#1111;"column_4"]</td></tr>\n" ;
&#125;
?>
</table>
Substitue your database table name for "table" and your column names for "column_1" etc.[/quote]
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Not What I Am Looking For

Post by icesolid »

I want to be able to print out 4 columns in tables, then make another row and have another 4 columns in tables printed, and etc.
User avatar
martin
Forum Commoner
Posts: 33
Joined: Fri Jun 28, 2002 12:59 pm
Location: Cambridgeshire

Post by martin »

See if this does it for you.

Code: Select all

<table>
<tr>
$cnt=1;
// loop for each item in array
while ($row = mysql_fetch_array($result)) &#123;
?>
<td>
<? echo $row&#1111;"somevalue"];?>
</td>
<?
if (!($cnt%4))&#123;
echo "</tr><tr>";
&#125;
$cnt++;
&#125;
?>
</tr>
</table>
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Thanks

Post by icesolid »

Thanks for the help, I can not belive I did not think of that.
Post Reply