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? Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
marklarah Posted March 9, 2008 Author Share Posted March 9, 2008 still no joy 'fraid. Same error Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2008 Share Posted March 9, 2008 try $row['score'] instead of $row['Score'] Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2008 Share Posted March 9, 2008 OK Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 10, 2008 Share Posted March 10, 2008 I've given my suggestion. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.