Jump to content

php table problem


pouncer

Recommended Posts

This is my table code:

 

echo "<table width=90% cellpadding=0 cellspacing=10 border=0 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\"><br>itemid: $item_id<a href=\"manageitem.php?item_id=$item_id\">Manage</a></td>";
if($i % 4 == 0) echo "</tr>";
}

echo "</table>";

 

But from this image: http://img249.imageshack.us/my.php?image=errorqw9.jpg

something is not right. the itemid should be like: 7,8,9,10.. etcwhy do my images appear in the wrong order, they appear in: 9,8,7,10 :s

Link to comment
https://forums.phpfreaks.com/topic/41539-php-table-problem/
Share on other sites

use while() not for()

<?php
        while($row = mysql_fetch_array($query)){
                $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\"><br>itemid: $item_id<a href=\"manageitem.php?item_id=$item_id\">Manage</a></td>";

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

Link to comment
https://forums.phpfreaks.com/topic/41539-php-table-problem/#findComment-201287
Share on other sites

What do you want printed out of the images?

 

Also, you can change the order by changing the sql statement to "ORDER BY item_id"

 

perfect, thanks. The images are items, when they click on Manage, it will take the user to that items manage page where they can edit the info for that particular item.

 

boo_lolly, using a while loop ok, but what about the $i ?

Link to comment
https://forums.phpfreaks.com/topic/41539-php-table-problem/#findComment-201291
Share on other sites

What do you want printed out of the images?

 

Also, you can change the order by changing the sql statement to "ORDER BY item_id"

 

perfect, thanks. The images are items, when they click on Manage, it will take the user to that items manage page where they can edit the info for that particular item.

 

boo_lolly, using a while loop ok, but what about the $i ?

 

sorry i missed that.

<?php
        $i = 1
        while($row = mysql_fetch_array($query)){
                $item_id = $row['item_id'];
                $cat = $row['category'];
                $_item = new uniqueItem($item_id, $cat);
                $img = $_item->getImageURL();

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

                (($i % 4 == 0)) ? ("<tr>") : (""));;
                echo "<td align=center><img src=\"$image\"><br>itemid: $item_id<a href=\"manageitem.php?item_id=$item_id\">Manage</a></td>";

                (($i % 4 == 0)) ? ("</tr>") : (""));
                $i++;
        }
?>

Link to comment
https://forums.phpfreaks.com/topic/41539-php-table-problem/#findComment-201504
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.