Jump to content

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in


Drumlegend

Recommended Posts

So I am getting this error and I don't understand what I'm doing wrong.

 

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in \\PDC3\sites\c\cupboard2stomach.com\public_html\index.php on line 102

 

 

<?php


    $recipes = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
ORDER BY RAND() LIMIT 4;
    ");


while ($recipe = mysql_fetch_assoc($recipes)) {
echo '<section id="recipeslide">';




echo "<a href='php/recipe.php?id=$recipe_id'><img src=\"{$recipe['image']}\" height=100 width=100 /></a><br />";
echo '</section>';


    }


echo '</section>';


echo '<section id="indexcenter">';


$recipegallery = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
ORDER BY RAND () LIMIT 10;
    ");


while ($recipegallery = mysql_fetch_assoc($recipegallery)) {
echo '<section id="recipegallery">';
$recipe_id = $recipegallery['id']; 
echo $recipegallery['name'];
echo '<br />';
echo "<a href='php/recipe.php?id=$recipe_id'><img src=\"{$recipegallery['image']}\" height=100 width=100 /></a><br />";


echo '<section id="description">';
echo $recipegallery['description'];
echo '</section>';


} 


echo '</section>';
echo '</section>';
?>

I have two queries running;

 

The first query pulls out 4 random recipes and displays them in a row at the top of the page.

 

The second one is meant to pull 10 random ones out that are display in a main container on the home page but at the moment it's only displaying one recipe and displaying that error.

 

Any thoughts?

 

Nevermind, the issue has been solved. 

 

$recipegallery = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
ORDER BY RAND () LIMIT 10;
    ");

 

The issue was that I needed to add s to $recipegallery

Nevermind, the issue has been solved. 

 

$recipegallery = mysql_query("

        SELECT `id`,`name`, `image`, `description`

        FROM `recipe` 

ORDER BY RAND () LIMIT 10;

    ");

 

The issue was that I needed to add s to $recipegallery

I'm not quite sure whether you can able to use the same varialbe as the result of mysql_query() and then to fetched it, like that:

$recipegallery = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
ORDER BY RAND () LIMIT 10;
    ");


while ($recipegallery = mysql_fetch_assoc($recipegallery)) {

 

I'm not quite sure whether you can able to use the same varialbe as the result of mysql_query() and then to fetched it, like that:

$recipegallery = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
ORDER BY RAND () LIMIT 10;
    ");


while ($recipegallery = mysql_fetch_assoc($recipegallery)) {

I'm sorry, I didn't understand that but the problem was resolved :)

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.