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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.