Jump to content

mysql_fetch_array


chriscloyd

Recommended Posts

okay i get this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fragradi/public_html/v.1/news.php on line 5

this is my whole code

[code]<?php
//news get while yaya
include("db.php");
$getnews = mysql_query("SELECT * FROM news ORDER by DESC");
while ($news = mysql_fetch_assoc($getnews)) {
$tile = $news['topic'];
$message = $news['message'];
$date = $news['date'];
$by = $news['by'];
echo '<table width="432" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2">'.$title.'</td>
  </tr>
  <tr>
    <td colspan="2">'.message.'</td>
  </tr>
  <tr>
    <td width="310">Posted By: '.$by.' on '.$date.'</td>
    <td width="122"><div align="right"><a href="comments/'.$nid.'">Comments (';
$count = mysql_query("SELECT * FROM comments WHERE nid = '$nid'");
$numoc = mysql_num_rows($count);
echo $numoc;
echo ' )</a> </div></td>
  </tr>
</table>';
}
?>[/code]
Link to comment
Share on other sites

You might want to check your query actually worked before trying to use the result from it. At the very least, use a die() to catch any errors....

[code=php:0]
$getnews = mysql_query("SELECT * FROM news ORDER by DESC") or die(mysql_error());
[/code]

Also... where is this $nid comming from? And you do realise using another query within a loop like that is a massive load on your database? Use a JOIN instead.
Link to comment
Share on other sites

Firstly, it's always a good idea to assign your query string to a variable, and then perform the MySQL operation on that variable. Also, it is a good idea to echo out the SQL error should it be failing. An example...

[code=php:0]$sql = "SELECT * FROM comments WHERE nid = '$nid'";[/code]

[code=php:0]$result = mysql_query($sql) OR DIE ("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());[/code]


This will print out...

[b]A fatal MySQL error occured[/b].
Query: SELECT * FROM comments WHERE nid = ''
Error: (err_no) The MySQL error description gets printed here.

Sorry Thorpe... didn't see you there!
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.