White_Lily Posted October 19, 2012 Share Posted October 19, 2012 Hi, I have a news box that whenever a person registers to the website, will update and you should see something like "New member has registered!" However, you do not see this. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in/home/sites/janedealsart.co.uk/public_html/index.phpon line 61. Here id the code for the news box: <div class="news"> <div class="newsHeading">News</div> <?php $news = select("*", "news", NULL, "id DESC", "1"); $display = mysql_fetch_assoc($news); echo '<a href="news.php?articleID='.$display["news_id"].'"><h2>'.$display["news_title"].'</h2></a>'; echo '<p>'.$display["news_content"].'</p>'; ?> </div> Here is the custom select() function: //Select function select($row = "*", $table, $where = NULL, $order = NULL, $limit = NULL) { $query = "SELECT ".$row." FROM ".$table; if($where != NULL){ $query .= " WHERE ".$where; }if($order != NULL){ $query .= " ORDER BY ".$order; }if($limit != NULL){ $query .= " LIMIT ".$limit; } $result = mysql_query($query); return $result; } mysql_fetch_assoc() has a valid variable in it, and the select function is fine since the rest of the site is able to get data without problems. I can't see why this is happening! :/ Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/269665-news-box-mysql_fetch_assoc-invalid-argument/ Share on other sites More sharing options...
White_Lily Posted October 19, 2012 Author Share Posted October 19, 2012 (edited) Solution: <div class="news"> <div class="newsHeading">News</div> <?php $news = select("*", "news", NULL, "news_id DESC", "1"); $display = mysql_fetch_assoc($news); echo '<a href="news.php?articleID='.$display["news_id"].'"><h2>'.$display["news_title"].'</h2></a>'; echo '<p>'.$display["news_content"].'</p>'; ?> </div> "id DESC" was supposed to be "news_id DESC" sorry for this >_< Edited October 19, 2012 by White_Lily Quote Link to comment https://forums.phpfreaks.com/topic/269665-news-box-mysql_fetch_assoc-invalid-argument/#findComment-1386252 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.