Renlok Posted January 2, 2007 Share Posted January 2, 2007 ive know idea why im getting this error when i load the page i get the error [quote]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/renlok/public_html/roe/news.php on line 13[/quote]it also then loads up the first entery in the database.the code for the page is[code]<?phpinclude("includes/header.php");echo "<center>";$newsquery = "SELECT * FROM news WHERE type='1'";$news = mysql_query($newsquery);$newsheader =<<<EOD <table width="75%" border="1" style="border-collapse: collapse"> <tr> <td>News</td> </tr>EOD;while($newinfo = mysql_fetch_array($news)){ $news = $newinfo['news']; $name = $newinfo['name']; $posted = $newinfo['posted']; $newsmain .=<<<EOD <tr> <td><u>$name</u><br>$news<p>Posted at: $posted</td> </tr>EOD;}$newsfooter = "</table>";$news =<<<NEWS $newsheader $newsmain $newsfooterNEWS;echo $news;echo "</center>";include("includes/footer.php");?>[/code]as someone asked before, all the db connection info is in 'includes/header.php' Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/ Share on other sites More sharing options...
kenrbnsn Posted January 2, 2007 Share Posted January 2, 2007 You're getting that error because you have some sort of error in your query. Change these lines[code]<?php$newsquery = "SELECT * FROM news WHERE type='1'";$news = mysql_query($newsquery);?>[/code]to[code]<?php$newsquery = "SELECT * FROM news WHERE type='1'";$news = mysql_query($newsquery) or die("Problem with the query: $newsquery<br>".mysql_error());?>[/code]This should output the error.Ken Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151406 Share on other sites More sharing options...
onlyican Posted January 2, 2007 Share Posted January 2, 2007 try this[code]<?phpinclude("includes/header.php");echo "<center>";$newsquery = "SELECT * FROM news WHERE type='1'";$news = mysql_query($newsquery);if($news){$newsheader =<<<EOD <table width="75%" border="1" style="border-collapse: collapse"> <tr> <td>News</td> </tr>EOD;while($newinfo = mysql_fetch_array($news)){ $news = $newinfo['news']; $name = $newinfo['name']; $posted = $newinfo['posted']; $newsmain .=<<<EOD <tr> <td><u>$name</u><br>$news<p>Posted at: $posted</td> </tr>EOD;}$newsfooter = "</table>";$news =<<<NEWS $newsheader $newsmain $newsfooterNEWS;echo $news;echo "</center>";}else{ echo "There was an error.<br />\n" .mysql_error();}include("includes/footer.php");?>[/code]IF the query failed, the error should show and say why Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151409 Share on other sites More sharing options...
wildteen88 Posted January 2, 2007 Share Posted January 2, 2007 There is a problem with your query. To find out what is wrong change this:[code]$news = mysql_query($newsquery);[/code]to this:[code]$news = mysql_query($newsquery) or die("Error with query <pre>{$newsquery}</pre>:<br />" . mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151410 Share on other sites More sharing options...
Renlok Posted January 2, 2007 Author Share Posted January 2, 2007 ive tryed all of your ideas but it always come back with the same thing thats no change but i did notice if i removed [code]while($newinfo = mysql_fetch_array($news))[/code]and jey left[code]$newinfo = mysql_fetch_array($news);[/code]in its place i dont get an error message but again only one result is returned. Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151423 Share on other sites More sharing options...
PFMaBiSmAd Posted January 2, 2007 Share Posted January 2, 2007 Know thy code (or at least proof read it) ::)The code in the while loop overwrites the [b]$news[/b] variable -[code]$news = $newinfo['news'];[/code]However, this [b]was[/b] the result resource from the query -[code]$news = mysql_query($newsquery);[/code] Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151432 Share on other sites More sharing options...
Renlok Posted January 2, 2007 Author Share Posted January 2, 2007 oh yeah lol im an idiot, thanks for that ^^ Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151434 Share on other sites More sharing options...
wildteen88 Posted January 2, 2007 Share Posted January 2, 2007 [quote author=Renlok link=topic=120681.msg495290#msg495290 date=1167749577]oh yeah lol im an idiot, thanks for that ^^[/quote]You're not the only one! We all missed it! Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151440 Share on other sites More sharing options...
Renlok Posted January 2, 2007 Author Share Posted January 2, 2007 yeah :) atleast someone was paying attention Link to comment https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/#findComment-151464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.