gaza165 Posted November 16, 2008 Share Posted November 16, 2008 try using this code.... <?php $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT username,skill FROM members WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo $row['username']."<br/>"; echo $row['skill']."<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691615 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 its been added but its still blank Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691619 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 are you using an include on player.php?? if so, what is the name of that file try using teh code below... <?php $sql = mysql_query("SELECT username,skill FROM members WHERE username = 'tester'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo $row['skill']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691620 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 i added the code and it told me this on the page "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)" Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691624 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 you need to make the connection to your db first, what is the name of the database and what is the name of the table inside the database??? take a look at the code properly and look to see if everything is referenced with the right name.. username password table name database name etc <?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $sql = mysql_query("SELECT username,skill FROM members WHERE username = 'tester'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo $row['skill']; } Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691627 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 the table name is "users" i added that and it still didnt work Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691632 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 try this code and let me know... <?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $sql = mysql_query("SELECT skill FROM users WHERE username = 'tester'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo $row['skill']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691634 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 thanks that worked, is there anyway i can have it display in a row kinda like Username: "username" Skill: "skill Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691642 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 <?php $sql = mysql_query("SELECT skill FROM users WHERE username = 'tester'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']; echo "Skill:".$row['skill']; // Then just carry on } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691647 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 ok but how do i change it so it dosnt show "testers" stats but the user who logged in? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691648 Share on other sites More sharing options...
corbin Posted November 16, 2008 Share Posted November 16, 2008 Change tester to be the username of the user who is currently logged in. Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691650 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 how would i go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691652 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 <?php $username = $_COOKIE['ID_my_site']; //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT username,skill FROM members WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']; echo "Skill:".$row['skill']; // Then just carry on } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691657 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 i replaced the last code with the the one above but now the page is blank ??? ??? this is the code i got going Name: <?php echo $_COOKIE['ID_my_site']; ?> <br> <?php // Connects to your Database mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $username = $_COOKIE['ID_my_site'] //this is the session variable containing the username of the person logged in. $sql = mysql_query("SELECT username,skill FROM members WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']; echo "Level:".$row['level']; echo "Skill:".$row['skill']; // Then just carry on } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691660 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 <?php $username = $_COOKIE['ID_my_site']; $sql = mysql_query("SELECT username,skill FROM members WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']; echo "Skill:".$row['skill']; // Then just carry on } ?> realised i missed a ; out try that Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691661 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 also forgot to change ur table name to users.. Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691664 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 Table 'members.members' doesn't exist thats what i got Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691665 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 <?php $username = $_COOKIE['ID_my_site']; $sql = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']; echo "Skill:".$row['skill']; // Then just carry on } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691667 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 thank you that worked great Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691668 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 That was probably the longest most un co-ordinated solution i have ever given at PHP Freaks... But, we got there in the end... dont forget to mark the topic as solved... good luck with the site.. Garry Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691670 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 one more think is there anyway to make it do the <br> function after each thing is displayed like 1 2 3 Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691671 Share on other sites More sharing options...
gaza165 Posted November 16, 2008 Share Posted November 16, 2008 <?php $username = $_COOKIE['ID_my_site']; $sql = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); while($row = mysql_fetch_array($sql)) { echo "Username:".$row['username']."<br/>"; echo "Skill:".$row['skill']."<br/>"; // Then just carry on } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691672 Share on other sites More sharing options...
Jiraiya Posted November 16, 2008 Author Share Posted November 16, 2008 thanks a lot for all the help Quote Link to comment https://forums.phpfreaks.com/topic/132982-solved-display-mysql-table-data/page/2/#findComment-691673 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.