Page 1 of 1

Limiting HTML Rows From An Query

Posted: Thu Jun 27, 2002 9:05 pm
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?

Posted: Thu Jun 27, 2002 10:41 pm
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]

Not What I Am Looking For

Posted: Fri Jun 28, 2002 12:03 pm
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.

Posted: Fri Jun 28, 2002 12:59 pm
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>

Thanks

Posted: Fri Jun 28, 2002 1:05 pm
by icesolid
Thanks for the help, I can not belive I did not think of that.