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.

Link to comment
Share on other sites

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 by White_Lily
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.