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
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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.