Drumlegend Posted May 12, 2013 Share Posted May 12, 2013 (edited) 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 May 12, 2013 by Drumlegend Quote Link to comment https://forums.phpfreaks.com/topic/277936-php-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource-in/ Share on other sites More sharing options...
Drumlegend Posted May 12, 2013 Author Share Posted May 12, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/277936-php-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource-in/#findComment-1429766 Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 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)) { Quote Link to comment https://forums.phpfreaks.com/topic/277936-php-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource-in/#findComment-1429769 Share on other sites More sharing options...
Drumlegend Posted May 12, 2013 Author Share Posted May 12, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/277936-php-warning-mysql_fetch_assoc-supplied-argument-is-not-a-valid-mysql-result-resource-in/#findComment-1429771 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.