chriscloyd Posted November 5, 2006 Share Posted November 5, 2006 okay i get this errorWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fragradi/public_html/v.1/news.php on line 5this is my whole code[code]<?php//news get while yayainclude("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] Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
gmwebs Posted November 5, 2006 Share Posted November 5, 2006 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! Quote Link to comment 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.