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
https://forums.phpfreaks.com/topic/45788-solved-table-probem/
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
https://forums.phpfreaks.com/topic/45788-solved-table-probem/#findComment-222429
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
https://forums.phpfreaks.com/topic/45788-solved-table-probem/#findComment-222433
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
https://forums.phpfreaks.com/topic/45788-solved-table-probem/#findComment-222434
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
https://forums.phpfreaks.com/topic/45788-solved-table-probem/#findComment-222435
Share on other sites

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.