berry05 Posted December 4, 2008 Share Posted December 4, 2008 i have the code to show data in the tables...but if there's 3 users signed up in the table three fields will show up..is there a way i can make it so the table only shows the fields for the user that's logged in only? like so the user only see's his own field? Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/ Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Show us some code and we can probably help ya. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706190 Share on other sites More sharing options...
revraz Posted December 4, 2008 Share Posted December 4, 2008 Use Sessions and link the ID. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706192 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 no problem.... heres the stats code that shows the users stats.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 { font-size: 18px; font-weight: bold; color: #FF0000; } .style2 { font-size: 16px; font-weight: bold; color: #000000; } --> </style> </head> <body> <p class="style1">STATS:</p> <p class="style2">Gold: <? mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $gold= $row["gold"]; echo "$gold<br>"; } ?> </p> <p class="style2">Water: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $water= $row["water"]; echo "$water<br>"; } ?></p> <p class="style2">Food: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $food= $row["food"]; echo "$food<br>"; } ?></p> <p class="style2">Health: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $health= $row["health"]; echo "$health<br>"; } ?></p> <p class="style2">Points: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $points= $row["points"]; echo "$points<br>"; } ?></p> <p class="style2"> </p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706194 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 Use Sessions and link the ID. is there a tut how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706195 Share on other sites More sharing options...
revraz Posted December 4, 2008 Share Posted December 4, 2008 Well one big problem you have right now is you are doing the exact same query multiple times, pulling all the columns each time, but only displaying 1 of them. Why not display all your items from the same query? Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706196 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Instead of just doing SELECT * FROM users, why not change it to SELECT * FROM users WHERE userid = currentuserid That way you only get the current user's information. The kicker is you need to know the userid, so like rev said, use a session when the user logs in to store his id and pull it out. session_start should provide examples. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706197 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 so i should add WHERE userid = currentuserid to this part...select * from users and then i should create a session and thats it? Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706199 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 so i should add WHERE userid = currentuserid to this part...select * from users and then i should create a session and thats it? Your missing the point, you need to define the userid on login in session. Then when you call that query use the session variable of userid in place of currentuserid. That will allow you to pull up the records only for that user id. Given that I am not sure how your script is suppose to work or does work, it may already be done. But also as rev pointed out I would use just one query as the first query will give you the items you need, no need for multiples. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706201 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 ok ill see what i can do...thxs for the help! Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706202 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 Only because I am bored, I decided to help a little. This is assuming that you do have a column for userid in table users: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 { font-size: 18px; font-weight: bold; color: #FF0000; } .style2 { font-size: 16px; font-weight: bold; color: #000000; } --> </style> </head> <body> <p class="style1">STATS:</p> <p class="style2">Gold: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users WHERE userid = " . intval($_GET['userid']); $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $gold= $row["gold"] . "<br />"; $water= $row["water"] . "<br />"; $food= $row["food"] . "<br />"; $health= $row["health"] . "<br />" $point= $row["points"] . "<br />" } echo "$gold<br>"; ?> </p> <p class="style2">Water: <?php echo "$water<br>"; ?></p> <p class="style2">Food: <?php echo "$food<br>"; ?></p> <p class="style2">Health: <?php echo "$health<br>"; ?></p> <p class="style2">Points: <?php echo "$points<br>"; ?></p> <p class="style2"> </p> </body> </html> That should help you out, I did $_GET for demonstration purposes, but that can be changed later on to SESSION when you get it setup. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706208 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 thank you so much for helping me but i'm getting a error saying... Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\omg.php on line 38 Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706215 Share on other sites More sharing options...
premiso Posted December 4, 2008 Share Posted December 4, 2008 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 { font-size: 18px; font-weight: bold; color: #FF0000; } .style2 { font-size: 16px; font-weight: bold; color: #000000; } --> </style> </head> <body> <p class="style1">STATS:</p> <p class="style2">Gold: <?php mysql_connect ("localhost","root",""); mysql_select_db ("game"); $sql = "select * from users WHERE userid = " . intval($_GET['userid']); $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $gold= $row["gold"]; $water= $row["water"]; $food= $row["food"]; $health= $row["health"]; $point= $row["points"]; } echo "$gold<br>"; ?> </p> <p class="style2">Water: <?php echo "$water<br>"; ?></p> <p class="style2">Food: <?php echo "$food<br>"; ?></p> <p class="style2">Health: <?php echo "$health<br>"; ?></p> <p class="style2">Points: <?php echo "$points<br>"; ?></p> <p class="style2"> </p> </body> </html> Missed the ; for some values, should work. Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706216 Share on other sites More sharing options...
berry05 Posted December 4, 2008 Author Share Posted December 4, 2008 .......it worked...wow...thank you so much man! ur da best!! Quote Link to comment https://forums.phpfreaks.com/topic/135556-solved-how-to-show-data-from-tables-for-certain-users/#findComment-706219 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.