Jump to content

Not Displaying errors


ShopMAster

Recommended Posts

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>&nbsp;&nbsp;(' . $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
Link to comment
https://forums.phpfreaks.com/topic/35382-not-displaying-errors/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167468
Share on other sites

[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>&nbsp;&nbsp;(' . $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]
Link to comment
https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-167936
Share on other sites

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>&nbsp;&nbsp;(' . $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]
Link to comment
https://forums.phpfreaks.com/topic/35382-not-displaying-errors/#findComment-168070
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.