problem with data_seek

I am doing a website for my fantasy football league. We are putting up a record book which will be a database driven page written in php. What I would like to do is to query the database and if there is information display it. If there is no information then I want it to say Never achieved.

Here is the code:

$con = mysql_connect($hostname, $username, $password)
OR DIE (‘Unable to connect to database! Please try again later.’);
$db = mysql_select_db($dbname, $con);

$query = “SELECT teamname, division_records.division, div_win, div_loss FROM division_records, owners WHERE owners.owner_id = division_records.owner_id AND division_records.year = 2011 ORDER BY division_records.division”;
$result = mysql_query($query);
$row = mysql_fetch_array($result);

if (!$result) {
echo ‘Never achieved’;
exit;
}

echo ‘

    ’;
    mysql_data_seek($result, 0);
    $row = mysql_fetch_array($result);
    while ($row = mysql_fetch_array($result)) {
    echo ‘
  1. ’ . $row[‘division’] . ': ’ . $row[‘teamname’] . ‘
    ’;
    echo 'Divisional Record: ’ . $row[‘div_win’] . ‘-’ . $row[‘div_loss’] . ‘
  2. ’;
    }
    echo ‘
’;
mysql_close($con);

The problem is if the query returns nothing then mysql_data_seek comes back with an error, if I dont include mysql_data_seek then the query displays on the second record, and it never says “Never achieved”

Any pointers would be greatly helpful.

Sponsor our Newsletter | Privacy Policy | Terms of Service