berry05 Posted December 15, 2008 Share Posted December 15, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/ Share on other sites More sharing options...
genericnumber1 Posted December 15, 2008 Share Posted December 15, 2008 SELECT item FROM users_item WHERE username = 'someusername' ? see: http://www.phpfreaks.com/forums/index.php/topic,95441.0.html Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-715543 Share on other sites More sharing options...
berry05 Posted December 15, 2008 Author Share Posted December 15, 2008 thxs man! ill try it tommorrow...getting tiredd now... Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-715549 Share on other sites More sharing options...
berry05 Posted December 15, 2008 Author Share Posted December 15, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716083 Share on other sites More sharing options...
9three Posted December 15, 2008 Share Posted December 15, 2008 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']; Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716100 Share on other sites More sharing options...
berry05 Posted December 15, 2008 Author Share Posted December 15, 2008 i have a session_start(); at the top of the page and i tried putting it where you wanted to to put it to and still doesnt work...but again...i have one on the top of the page.. Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716110 Share on other sites More sharing options...
9three Posted December 15, 2008 Share Posted December 15, 2008 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'] } Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716132 Share on other sites More sharing options...
justinh Posted December 15, 2008 Share Posted December 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716135 Share on other sites More sharing options...
berry05 Posted December 15, 2008 Author Share Posted December 15, 2008 i do...i have 3 tables...one called users and one called users_items and one called items.. Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716144 Share on other sites More sharing options...
berry05 Posted December 15, 2008 Author Share Posted December 15, 2008 so what should i do now? Quote Link to comment https://forums.phpfreaks.com/topic/136990-can-i-have-1-field-that-has-a-name-and-show-all-info-for-that-name/#findComment-716260 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.