Jump to content

adding data into a table


pouncer

Recommended Posts

At the moment, I've got something like this.

 

echo "
<table width=90% cellpadding=0 cellspacing=1 border=0 align=center>
<tr>
<th>Item</th>
<th>Description</th>
</tr>";


while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
echo "
<tr>
	<td>$item_name</td>
	<td>$item_description</td>

</tr>";
}

echo "</table>";

 

But I want to change the table layout. I want to make a 3 by 3 table (9 slots) and put all the data in 1 slot at a time, can someone show me how to change the table layout?

Link to comment
https://forums.phpfreaks.com/topic/40346-adding-data-into-a-table/
Share on other sites

Try:

 

<?php

echo "<table width=90% cellpadding=0 cellspacing=1 border=0 align=center>\n";
echo "<tr>\n";
echo "<th>Item</th>\n";
echo "<th>Description</th>\n";
echo "<th>Slot 3</th>\n";
echo "</tr>";


for ($i = 0; $row = mysql_fetch_array($sql, MYSQL_ASSOC); $i++)
{
if($i%3 == 0)
	echo "<tr>";
echo "<td>".$item_name."</td>";
echo "<td>".$item_description."</td>";
echo "<td>Slot 3</td>";
if($i%3 == 0)
	echo "</tr>";
}

echo "</table>";

?>

 

 

Orio.

ahhh, i see now mate. very nice.

 

I was looking at how i could add a counter for each record like you added $i in the for loop.

 

thanks!

 

and also % is mod? which calculates the remainder?i just noticed you have if($i%3 == 0) twice :s

and also, shouldnt i start at 1? since if its 0, it will display 0 1 2 3 which is 4?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.