473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

I'm trying a php code but i don't know what's wrong!

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:


Expand|Select|Wrap|Line Numbers
  1. $inventory = array();
  2. $query = sprintf("SELECT id, item_id, quantity FROM user_items WHERE user_id = '%s'",
  3.         mysql_real_escape_string($userID));
  4. $result = mysql_query($query);
  5. while($row = mysql_fetch_assoc($result)) {
  6.      $item_query = sprintf("SELECT name FROM items WHERE id = '%s'",
  7.         mysql_real_escape_string($row['item_id']));
  8.     $item_result = mysql_query($item_query);
  9.     list($row['name']) = mysql_fetch_row($item_result);
  10.     array_push($inventory,$row);
  11. }


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.
Sep 14 '10 #1
1 1242
Dormilich
8,658 Expert Mod 8TB
I think you’re better off with a JOIN.
Expand|Select|Wrap|Line Numbers
  1. SELECT items.name FROM items
  2. JOIN user_items ON user_items.item_id = items.id
  3. WHERE user_items.user_id = ?
after that you can get the result by using PDO and its fetchAll() method
Sep 14 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
4
by: Dan K. | last post by:
Hi NG, first of all i am new to OOP and C# so maybe thats my whole problem :) i wrote a small timer application, like i did if i was starting with programming in vb long time ago. the vb...
3
by: mahsa | last post by:
Hi do you know whats wrong with this code? <asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');"...
4
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the...
2
by: Tiruak | last post by:
Hi there. Thanks in advance for the people reading and trying to help. I'm very begginer using flash and action script, and I tryed to do this one navigation menu. Since I dont have experience...
1
by: ramyap2 | last post by:
<html> <body> <%@ page import="java.sql.*" %> <% Connection con=null; Statement st=null; ResultSet rs= null;
0
Elias Alhanatis
by: Elias Alhanatis | last post by:
Hello!! I have installed the latest Apache version on Windows Vista and it works fine as a service , and i also get the expected screen on 'localhost'. But when i try to access the web pages from...
5
by: mingle | last post by:
Hi, I have a .pm file, which was placed within my site when it got hacked, i've never used perl before, but after some googling I thought I'd ask the pros at these forums. Heres the code which...
2
by: sailormoon | last post by:
this information i put in data.txt 11221 MOHD IRFAN 80 70 11222 NURUL FITRAH 80 90 11223 MOHD FARHAN 70 80 11224 WAFFIN WARDAH 80 60 11225 SYAMSUL 50 50 99999 TAMAT 0 0 #include<fstream.h>
2
by: sometingsometing | last post by:
hi, I am new and dont know what went wrong. from Tkinter import * import tkMessageBox from pysqlite2 import dbapi2 as sqlite class door: global simpleprint
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.