Jump to content

News Box Mysql_Fetch_Assoc() Invalid Argument


White_Lily

Recommended Posts

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.

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 >_<

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.