Jump to content

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


berry05

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. 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.