CloudSex13 Posted May 13, 2009 Share Posted May 13, 2009 For some reason, the variable $itemURL outputs only the last item fetched's URL, and displays that one URL for all data returned. I want each item's unique URL displayed at the end of the path instead. Could anyone see a reason as to why this does not work? Something a little less important too that doesn't work is the ORDER BY ItemName code - it will not order the returned data by it's name either ASC or DESC. Any suggestions? :/ $query = mysql_query("SELECT Inventory FROM Users WHERE Username='$cookie' LIMIT 1"); $getquery = mysql_fetch_assoc($query); $inventory = substr($getquery['Inventory'], 0, -1); $itemnames = array(); $query2 = mysql_query("SELECT * FROM Items WHERE ItemID IN (".$inventory.") AND ItemType='Box' ORDER BY ItemName"); $inventory = explode(",",$inventory); $inventory= array_count_values($inventory); while ($row = mysql_fetch_assoc($query2)) { $itemnames[$row['ItemID']] = $row['ItemName']; $itemurl = $row['ItemURL']; } foreach ($inventory as $key => $count) { $stuff .= "<div class=\"item\"><img src=\"http://www.example.com/images/".$itemURL."\" /><strong>".$itemnames[$key]." (".$count.")</strong><br /><a href=\"action.php?do=remove&itemid=".$key."\">Remove</a></div>"; } Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 You don't really need to go off the foreach loop if you want to sort like that. Just do it in the while loop. Also, it's good to define your variables outside of loops (like $stuff). One of the reason why I use a single quote to start off a PHP string is because I tend to use double quotes around HTML elements and starting a PHP string off with a single quote is helpful to avoid escaping double quotes. Try this. I believe it should work. $query = mysql_query("SELECT Inventory FROM Users WHERE Username='$cookie' LIMIT 1"); $getquery = mysql_fetch_assoc($query); $inventory = substr($getquery['Inventory'], 0, -1); $query2 = mysql_query("SELECT * FROM Items WHERE ItemID IN (".$inventory.") AND ItemType='Box' ORDER BY ItemName"); $inventory = explode(',',$inventory); $inventory= array_count_values($inventory); $stuff = ''; while ($row = mysql_fetch_assoc($query2)) { $stuff .= '<div class="item"><img src="http://www.example.com/images/"'.$row['ItemURL'].'" /><strong>'.$row['ItemName'].'('.$inventory[$row['ItemID']].')</strong><br /><a href="action.php?do=remove&itemid='.$row['ItemID'].'">Remove</a></div>'; } Quote Link to comment Share on other sites More sharing options...
CloudSex13 Posted May 13, 2009 Author Share Posted May 13, 2009 You've officially been knighted as my favorite superhero. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.