marklarah Posted March 9, 2008 Share Posted March 9, 2008 <? $resulta = mysql_query("SELECT * FROM `Score` ORDER BY `Score` DESC LIMIT 5"); while ($row = mysql_fetch_array($resulta)){ $playerid = $row['userid']; $resulta = mysql_query("SELECT * FROM `users` WHERE `userid` = '$playerid'"); $bob = mysql_fetch_array($resulta); $player = $bob['username']; echo '<b>'.$player.'</b>: '.$row['Score'].'<br>'; } ?> I just get the first row of the highest player. I have to do this because it only inserts the user id's into the DB, and the ids with the names are in another table. So hewp. Maybe a function? Link to comment https://forums.phpfreaks.com/topic/95290-mysql/ Share on other sites More sharing options...
pocobueno1388 Posted March 9, 2008 Share Posted March 9, 2008 Are you asking how to combine these queries? If so...you can do it like this: <?php $resulta = mysql_query("SELECT s.userid, u.username FROM Score s LEFT JOIN users u ON u.userid=s.userid ORDER BY SCORE DESC LIMIT 5"); while ($row = mysql_fetch_array($resulta)){ echo '<b>'.$row['username'].'</b>: '.$row['Score'].'<br>'; } ?> If thats not what you want, explain a little more. Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488057 Share on other sites More sharing options...
marklarah Posted March 9, 2008 Author Share Posted March 9, 2008 hmm Notice: Undefined index: Score in /home/ammostar/public_html/boards/scores.php on line 117 Robtcee13: Notice: Undefined index: Score in /home/ammostar/public_html/boards/scores.php on line 117 Robtcee13: Notice: Undefined index: Score in /home/ammostar/public_html/boards/scores.php on line 117 Robtcee13: Notice: Undefined index: Score in /home/ammostar/public_html/boards/scores.php on line 117 Robtcee13: Notice: Undefined index: Score in /home/ammostar/public_html/boards/scores.php on line 117 Robtcee13: Not sure here... Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488065 Share on other sites More sharing options...
pocobueno1388 Posted March 9, 2008 Share Posted March 9, 2008 Oops, I forgot to select "Score" from the table in the query. Change it to this: <?php $resulta = mysql_query("SELECT s.userid, s.score, u.username FROM Score s LEFT JOIN users u ON u.userid=s.userid ORDER BY SCORE DESC LIMIT 5"); while ($row = mysql_fetch_array($resulta)){ echo '<b>'.$row['username'].'</b>: '.$row['Score'].'<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488068 Share on other sites More sharing options...
marklarah Posted March 9, 2008 Author Share Posted March 9, 2008 still no joy 'fraid. Same error Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488085 Share on other sites More sharing options...
Barand Posted March 9, 2008 Share Posted March 9, 2008 try $row['score'] instead of $row['Score'] Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488087 Share on other sites More sharing options...
marklarah Posted March 9, 2008 Author Share Posted March 9, 2008 Nah, its definitely Score. Its something to do with the actually fetching bit, because it only fetches the first row, but multiple times, with an error. Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488093 Share on other sites More sharing options...
Barand Posted March 9, 2008 Share Posted March 9, 2008 OK Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488095 Share on other sites More sharing options...
marklarah Posted March 10, 2008 Author Share Posted March 10, 2008 so any suggstions? should i just do what i did origionally, in a function? Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488096 Share on other sites More sharing options...
Barand Posted March 10, 2008 Share Posted March 10, 2008 I've given my suggestion. Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488099 Share on other sites More sharing options...
marklarah Posted March 10, 2008 Author Share Posted March 10, 2008 I've given my suggestion. The row is definitely uppercase the first letter. Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488314 Share on other sites More sharing options...
Barand Posted March 10, 2008 Share Posted March 10, 2008 I guess I'll just have to spell it for you then as you be bothered to even try it This code fails when $row['Score'] is used <?php error_reporting (E_ALL); include 'db.php'; /** THE TABLE ********************************** DROP TABLE IF EXISTS `test`.`tbl_score`; CREATE TABLE `tbl_score` ( `Player` varchar(40) default NULL, `Score` int(10) unsigned default NULL ) ***********************************************/ $sql = "SELECT s.player, s.score FROM tbl_score s"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { echo $row['player'], ' ', $row['Score'], '<br />'; } ?> Gives --> Brak Notice: Undefined index: Score in C:\Inetpub\wwwroot\test\noname5.php on line 18 IronMaiden Notice: Undefined index: Score in C:\Inetpub\wwwroot\test\noname5.php on line 18 NINJA Notice: Undefined index: Score in C:\Inetpub\wwwroot\test\noname5.php on line 18 Reaper Notice: Undefined index: Score in C:\Inetpub\wwwroot\test\noname5.php on line 18 Whereas this works because "s.score" as used in the query is Lowercase even though the column in the table is "Score" <?php error_reporting (E_ALL); include 'db.php'; /** THE TABLE ********************************** DROP TABLE IF EXISTS `test`.`tbl_score`; CREATE TABLE `tbl_score` ( `Player` varchar(40) default NULL, `Score` int(10) unsigned default NULL ) ***********************************************/ $sql = "SELECT s.player, s.score FROM tbl_score s"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { echo $row['player'], ' ', $row['score'], '<br />'; // NOTE : Lcase score to match the colname from the query } ?> Gives --> Brak 8850 IronMaiden 99250 NINJA 95457 Reaper 70100 Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-488738 Share on other sites More sharing options...
marklarah Posted March 21, 2008 Author Share Posted March 21, 2008 Oh dude thanks...I did it i forgot to post...I fixed it through a function. But thanks though anyway :D Link to comment https://forums.phpfreaks.com/topic/95290-mysql/#findComment-497282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.