not a valid MySQL result resource

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikes1471
Forum Commoner
Posts: 88
Joined: Sat Jan 24, 2009 3:29 pm

not a valid MySQL result resource

Post by mikes1471 »

Hi

I get this error message:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/redlemons.com/httpdocs/new/albums.php on line 18

and despite this message I cant see where the problem is in my code:

Code: Select all

<table cellpadding='7' width='100%'>
    <tr>
        <td>
        <font face='arial' size='4'>
        My Albums<p>
        <font size='2'>
        ";
        $id = $_SESSION['id'];
        $album = mysql_query("SELECT * FROM albums WHERE userid='$id'");
        
        echo "<table width='50%'>";
        while ($row = mysql_fetch_assoc($album))
        {
        echo "
        <tr>
            <td>
            <img src='store/".$row['cover']."' width='100' height='100'>
            </td>
            <td>
            <b>".$row['name']."</b><br>
            ".$row['description']."
            </td>
        </tr>
        ";
        }
        echo "</table>
I wonder if someone could help me with this as im stuck!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: not a valid MySQL result resource

Post by califdon »

There may be no problem with your code. That error message means that your query didn't return a valid result dataset. That is often not a code problem, but a data problem. You will never know if you don't trap the error MySQL returns to you. Change your query code to this:

Code: Select all

$sql = "SELECT * FROM albums WHERE userid='$id'";
$album = mysql_query($sql) or die(mysql_error() . "<br/> $sql");
That is likely to return all the information you need to determine the problem and its solution.
Post Reply