Page 1 of 1

Finally working but...

Posted: Thu Sep 17, 2009 9:57 am
by timecatcher
Ok well the 'inventory' script I was designing to allow only 4 of each item per row now works however after the first picture the rest all come out as broken links...even though the number of broken links adds up to the number of pictures that should be displaying.

I want to know where I've gone wrong please:

Code: Select all

<?php
require("../includes/config.php");
echo "$open";
if(isset($loggedout))
{
die("$loggedout");
}
//Makes the username's first letter uppercase.
    $ucusername = ucfirst($username);
echo "<h1>$ucusername's House Storage</h1>";
 
//Checks in the 'inventory' whether there are any items belonging to the user with the ID set to their account.
    $query = mysql_query("SELECT * FROM storage WHERE userid='$id' LIMIT 10");
 
    echo "<table border=0>";
    $rows = mysql_fetch_array($query);
    $items = mysql_query("SELECT * FROM items WHERE id='$rows[itemid]'");
    for($x=0;$x<mysql_num_rows($query);$x++)
        {
        $items1 = mysql_fetch_array($items);
        
        if($x%4==0)
            {
            echo "<tr></tr>";
            }
            echo "<td><img src='http://kurukolands.co.uk/images/items/$items1[image]'><br /><font color='green'>$items1[name]</font></td>";
        }
    echo "</table>";
 
echo "$close";
?>

Re: Finally working but...

Posted: Thu Sep 17, 2009 10:00 am
by jackpf
What's the src of the image(s) in the source of the page?

Do those images really exist?

Re: Finally working but...

Posted: Thu Sep 17, 2009 10:03 am
by timecatcher
Yes they exist since the endings are coming directly from a database. The first of which appears fine and as it should the other 4 however do not appear and are left with 4 broken icons and when I look at the properties it doesn't display the ending of /items/ ...so Im a bit stuck.

Timecatcher.

Re: Finally working but...

Posted: Thu Sep 17, 2009 10:26 am
by jackpf
That's because you're looping through your first query (in the for loop), but using your second query to fetch the values...

I think maybe you want to put

Code: Select all

$rows = mysql_fetch_array($query);
$items = mysql_query("SELECT * FROM items WHERE id='$rows[itemid]'");
in the for() loop as well.

Although I'm sure you could achieve this with just one query.

Re: Finally working but...

Posted: Thu Sep 17, 2009 10:45 am
by timecatcher
Working now thanks :), I understand where it went wrong. It was only running the query once.