ashlegen Posted September 14, 2010 Share Posted September 14, 2010 Hi guys.I've got a problem.I'm building my php browsergame and i'm stuck into the inventory page.I have a code that seems ok to me but it won't work.Here it is: $inventory = array(); $query = sprintf("SELECT id, item_id, quantity FROM user_items WHERE user_id = '%s'", mysql_real_escape_string($userID)); $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $item_query = sprintf("SELECT name FROM items WHERE id = '%s'", mysql_real_escape_string($row['item_id'])); $item_result = mysql_query($item_query); list($row['name']) = mysql_fetch_row($item_result); array_push($inventory,$row); } I've spotted the problem.The $inventory array is empty.I checked it with if(empty($inventory)) .Thanks in advance and keep in mind that I'm a noob yet. Quote Link to comment Share on other sites More sharing options...
mds1256 Posted September 14, 2010 Share Posted September 14, 2010 Your SQL script is wrong, when using '%s' you need to use LIKE rather than = Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 No, that's a formatted string placeholder, not a wildcard operator. Are you sure $userID has a valid value? Have you tried echo $query;? Quote Link to comment Share on other sites More sharing options...
mds1256 Posted September 14, 2010 Share Posted September 14, 2010 No, that's a formatted string placeholder, not a wildcard operator. Sorry your correct, i missed the 2nd part of the line below Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 14, 2010 Share Posted September 14, 2010 What exactly are you trying to make that code chunk do? Is it expected to return multiple records from the database? Quote Link to comment Share on other sites More sharing options...
ashlegen Posted September 15, 2010 Author Share Posted September 15, 2010 Yes.I'm trying to get all of the item ids associated with a specific user id into an array.I'll keep you up to date and thanks for answering. Quote Link to comment Share on other sites More sharing options...
ashlegen Posted September 15, 2010 Author Share Posted September 15, 2010 No, that's a formatted string placeholder, not a wildcard operator. Are you sure $userID has a valid value? Have you tried echo $query;? Oh man!I checked now and i've got the poblem.You were right.$uerID never had a value because i forgot the session_start() thing at the begiing of the document.Thanks again guys and I'm looking forward to ask more here.Cheers! 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.