Jump to content

can i have 1 field that has a name and show all info for that name?


Recommended Posts

hello!

 

i have two fields...table is called users_item and has two fields which is username and item..i tried figuring this out but its not working...im trying to make it so when that logged in user lets say berry05  logs in he see's his inventory...so when that username shows up it shows all the items that username has.....but how do i do that..?

 

thxs!

ok this is the code i added...

$queryyy = "SELECT item FROM users_items WHERE username='$username'";
$result11 = mysql_query($queryyy);
$roww = mysql_fetch_assoc($result11);
$_SESSION['inventory'] = $roww['inventory'];

 

and i got no errors and no item showing...

 

i put this on my index page too..

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("textgame") or die(mysql_error());

echo " " . $_SESSION['inventory'];

 

You need to have a session_start(); before you do anything with a session. You can do something like this:

 

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("textgame") or die(mysql_error());

session_start();
echo " " . $_SESSION['inventory'];

I'm assuming you want a list of the inventory, so try using mysql_fetch_array

 

$queryyy = "SELECT item FROM users_items WHERE username='$username'";
$result11 = mysql_query($queryyy);
while ($field = mysql_fetch_array($result11))
{
$_SESSION['inventory'] = $field['inventory']
}

Also, I would recommend reading up on database normalization. It seems like your situation would benefit with 2 tables instead of one. ie.

 

tbl_users

tbl_items

 

This would make it a whole lot easier to update and maintain. Just an idea though. 

 

 

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.