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?

 

Edited by Drumlegend
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)) {
Link to comment
Share on other sites

 

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 :)

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.