0

I have following code..

$query = "SELECT quote, author FROM quotes ORDER BY id DESC";
$resut = mysql_query($query, $connection) or die(mysql_error());

echo $result; //for debuggin purpose

while($result_set =  mysql_fetch_array($result)) {      
    echo '<div class="pullquote">';
    echo $result_set['quote'];
    echo ' - ';
    echo $result_set['author'];
    echo '</div>';
}

and this doesn't works! The table is not empty FYI, all I see in the output is:

Resource id #9

I am not being able to figure out what this Resource id #9 means. As I tested SELECT quote, author FROM quotes ORDER BY id DESC in phpmyadmin, that just works fine and produces desired result, but not in here. I wonder what is wrong with the code or something?

If I do following,

$array = mysql_fetch_assoc($result);
var_dump ($array);

It returns, bool(false). What does that mean here?

Tom
  • 316
  • 2
  • 9
  • 30

1 Answers1

3

What is a "Resource"?

There's nothing wrong with Resource id #9 (this just means you have a resource). Note the documentation on this topic:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

So if you have "Resource," it means your query didn't fail.

Watch for Typos

Additionally, you are setting $resut, and attempting to access $result. Note the missing "l".

Community
  • 1
  • 1
Sampson
  • 265,109
  • 74
  • 539
  • 565