Jump to content

[SOLVED] table probem


pouncer

Recommended Posts

this is supposed to output a table, with 3 items per row.. but it messes up for some reason.

heres my code

 

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

						for ($i = 1; $row = mysql_fetch_array($qry, MYSQL_ASSOC); $i++) {
							$item_id = $row['item_id'];
							$cat = $row['category'];

							$_item = new uniqueItem($item_id, $cat);
							$img = $_item->getImageURL();

							if ($img != "") $image = "../" . $img;
							else $image = "../index_images/create_avatar.gif";

							if ($i % 4 == 0) echo "<tr>";

							echo "<td align=center>
										<img src=\"$image\"> $i
										<br>
										<a href=\"manageitem.php?item_id=$item_id\">Manage</a>
										<br>
										<a href=\"delete_item.php?item_id=$item_id\">Delete</a>


								</td>";

							if($i % 4 == 0) echo "</tr>";
						}

						echo "</table>";

 

but my problem is, say i have 7 items , it displays like this on the page

<item1> <item 2> <item 3>

<item 4>

<item5> <item 6> <item 7>

 

it shud be like this..

 

<item1> <item 2> <item 3>

<item 4> <item 5> <item 6>

<item7>

 

whats the problem guys?

Link to comment
Share on other sites

thats inside the loop!

if ($i % 4 == 0) echo "<tr>";

							echo "<td align=center>
										<img src=\"$image\"> $i
										<br>
										<a href=\"manageitem.php?item_id=$item_id\">Manage</a>
										<br>
										<a href=\"delete_item.php?item_id=$item_id\">Delete</a>


								</td>";

							if($i % 4 == 0) echo "</tr>";

 

i want it to display by  a 3 x 3 table.. all items going down the page

Link to comment
Share on other sites

<table width="200" border="1">

  <tr>

    <td></td>

    <td></td>

    <td></td>

  </tr>

  <tr>

    <td></td>

    <td></td>

    <td></td>

  </tr>

  <tr>

    <td></td>

    <td></td>

    <td></td>

  </tr>

</table>

 

already have googled it...

 

Link to comment
Share on other sites

                  <table width=90% cellpadding=0 cellspacing=10 border=0 align=center><tr><th></th><th></th><th></th></tr><td align=center>
										<img src="../thumbnail.php?im=collection_items/John_images/godfather1.jpg">
										<br>
										<a href="manageitem.php?item_id=7">Manage</a>
										<br>
										<a href="delete_item.php?item_id=7">Delete</a>


								</td><td align=center>
										<img src="../thumbnail.php?im=collection_items/John_images/carlitos-way.jpg">
										<br>
										<a href="manageitem.php?item_id=8">Manage</a>
										<br>
										<a href="delete_item.php?item_id=8">Delete</a>


								</td><td align=center>
										<img src="../thumbnail.php?im=collection_items/John_images/godfather1.jpg">
										<br>
										<a href="manageitem.php?item_id=9">Manage</a>
										<br>
										<a href="delete_item.php?item_id=9">Delete</a>


								</td><tr><td align=center>
										<img src="../index_images/create_avatar.gif">
										<br>
										<a href="manageitem.php?item_id=12">Manage</a>
										<br>
										<a href="delete_item.php?item_id=12">Delete</a>


								</td></tr><td align=center>
										<img src="../index_images/create_avatar.gif">
										<br>
										<a href="manageitem.php?item_id=19">Manage</a>
										<br>
										<a href="delete_item.php?item_id=19">Delete</a>


								</td></table>                  </span></span><br>
                  <span class="style15">                  </span><br>

Link to comment
Share on other sites

try

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

$i = 0;
while ($row = mysql_fetch_array($qry, MYSQL_ASSOC)) {
$item_id = $row['item_id'];
$cat = $row['category'];

$_item = new uniqueItem($item_id, $cat);
$img = $_item->getImageURL();

if ($img != "") $image = "../" . $img;
else $image = "../index_images/create_avatar.gif";

if ($i % 3 == 0) echo "<tr>";

echo "<td align=center>
			<img src=\"$image\"> $i
			<br>
			<a href=\"manageitem.php?item_id=$item_id\">Manage</a>
			<br>
			<a href=\"delete_item.php?item_id=$item_id\">Delete</a>


	</td>";
$i++;
if ($i % 3 == 0) echo "</tr>";
}

echo "</table>";
?>

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.