ShopMAster Posted January 23, 2007 Share Posted January 23, 2007 I'm having a little problem when I'm trying to display recent games from my database.It happens when a players name has been changed. What I'm trying to do is display the last 5 wins for a particular player, but if the opponent they played has had a name change, it gives me an error. Is there anyway I can not display that game if there is no id for the opponent? Or a way I can get the id for an opponent who's name has changed? Maybe I can capture it somehow when a person enters a game? I don't know.Here is the code to display the last 5 games (This is an include file in the player's profile page hence the .$player[player_name].):[code]<table width="100%" border="0"><?php$res = mysql_query("SELECT * FROM random_games where random_winner = '" .$player[player_name]."' ORDER BY id DESC Limit 5"); while ( $row = mysql_fetch_row($res) ) { $loser = mysql_result(mysql_query("select id from players where player_name = '".$row[3]."'"),0,"id"); $winner = mysql_result(mysql_query("select id from players where player_name = '".$row[1]."'"),0,"id"); $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //switch background color echo'<tr bgcolor='.$bg.'><td width="50%"><font face="Verdana" size="1"><a href="profile.php?id='.$loser.'">' . $row[3] .'</a> (' . $row['2'] .'-' . $row['4'] .')</td> <td width="50%"><font face="Verdana" size="1"><a href="gamedetails.php?id=' . $row['0'] .'"><u>View Details</u><a/></font></td></tr>'; } if ( mysql_num_rows($res) == 0 ) echo '<tr><td>There are no wins for this player.</td></tr>'; else { echo ''; } ?> </table>[/code]The error I'm getting is the following: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 7 in D: ../usr_wins.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/ Share on other sites More sharing options...
fenway Posted January 23, 2007 Share Posted January 23, 2007 Well, yes, you're assuming such an ID will be found, and automatically trying to use the first record of the result set -- hence the error when it doesn't exist. Simply issue the query, but check to see how many rows came back -- if 1, good, if 0, then display something else to the user. Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167468 Share on other sites More sharing options...
ShopMAster Posted January 23, 2007 Author Share Posted January 23, 2007 What would the syntax be to do that, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167569 Share on other sites More sharing options...
paul2463 Posted January 24, 2007 Share Posted January 24, 2007 [code]<?php$res = mysql_query("SELECT * FROM random_games where random_winner = '" .$player[player_name]."' ORDER BY id DESC Limit 5");if ( mysql_num_rows($res) > 0 ){while ( $row = mysql_fetch_row($res) ) { if ($row[3]!="") { $loser = mysql_result(mysql_query("select id from players where player_name = '".$row[3]."'"),0,"id"); } else { $loser = ''; } $winner = mysql_result(mysql_query("select id from players where player_name = '".$row[1]."'"),0,"id"); $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //switch background color echo'<tr bgcolor='.$bg.'><td width="50%"><font face="Verdana" size="1"><a href="profile.php?id='.$loser.'">' . $$row[3] .'</a> (' . $row['2'] .'-' . $row['4'] .')</td> <td width="50%"><font face="Verdana" size="1"><a href="gamedetails.php?id=' . $row['0'] .'"><u>View Details</u><a/></font></td></tr>'; }}else{ echo '<tr><td>There are no wins for this player.</td></tr>';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167936 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 Won't there be the same issue for winner? Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167999 Share on other sites More sharing options...
ShopMAster Posted January 24, 2007 Author Share Posted January 24, 2007 Still giving me the same error:Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 6 in ../usr_wins.php on line 10 Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168017 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 Correct -- you need to check the number of rows back from every mysql_query() before mysql_result(). Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168024 Share on other sites More sharing options...
ShopMAster Posted January 24, 2007 Author Share Posted January 24, 2007 how would you do that? Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168026 Share on other sites More sharing options...
paul2463 Posted January 24, 2007 Share Posted January 24, 2007 try this[code]<?php$res = mysql_query("SELECT * FROM random_games where random_winner = '" .$player[player_name]."' ORDER BY id DESC Limit 5");if ( mysql_num_rows($res) > 0 ){while ( $row = mysql_fetch_row($res) ) { $result = mysql_query("select id from players where player_name = '".$row[3]."'"); if (mysql_num_rows($result)>0) { $loser = mysql_result($result,0,"id"); } else { $loser = ""; } $result1 = mysql_query("select id from players where player_name = '".$row[1]."'"); if (mysql_num_rows($result1)>0) { $winner = mysql_result($result1,0,"id"); } else { $winner = ""; } $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); //switch background color echo'<tr bgcolor='.$bg.'><td width="50%"><font face="Verdana" size="1"><a href="profile.php?id='.$loser.'">' . $row[3] .'</a> (' . $row['2'] .'-' . $row['4'] .')</td> <td width="50%"><font face="Verdana" size="1"><a href="gamedetails.php?id=' . $row['0'] .'"><u>View Details</u><a/></font></td></tr>'; }}else{ echo '<tr><td>There are no wins for this player.</td></tr>';}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168070 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 That looks about right. Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168087 Share on other sites More sharing options...
ShopMAster Posted January 24, 2007 Author Share Posted January 24, 2007 Thanks Guys it worked. Much appreciation to Paul and fenway. Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168189 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 Paul did most of the work... Quote Link to comment https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168484 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.