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