woodplease Posted January 25, 2012 Share Posted January 25, 2012 I've recently re-uploaded a website i created last year. when it was last online, everything worked perfectly, but now i'm finding that some of my pages that are supposed to retrieve data from a table are not returning anything. i havnt changed any code, and i have confirmed that there is data in the table. my c ode is as follows <?php $news=mysql_query("SELECT * FROM news ORDER BY date DESC") or die ("Unable to load latest site news"); $numofrows = mysql_num_rows($news); echo $numofrows; for($t = 1; $t<$numofrows; $t++){ $latest= mysql_fetch_array($news); $news_date = date("Y-m-d",$latest['date']); echo"<div class='rightLinks'>".$news_date."</div>"; echo $latest['article_title']."</h2><p>".$latest['article_text']; } ?> i've added the "echo $numofrows" just to check that it is getting something from the database, and the correct number of rows is displayed. if anyone can see any problems, any help would be greatly appreciated thanks Quote Link to comment https://forums.phpfreaks.com/topic/255755-no-data-is-being-pulled-from-database/ Share on other sites More sharing options...
scootstah Posted January 25, 2012 Share Posted January 25, 2012 Try this while($latest = mysql_fetch_assoc($news)) { $news_date = date("Y-m-d",$latest['date']); echo"<div class='rightLinks'>".$news_date."</div>"; echo $latest['article_title']."</h2><p>".$latest['article_text']; } Quote Link to comment https://forums.phpfreaks.com/topic/255755-no-data-is-being-pulled-from-database/#findComment-1311062 Share on other sites More sharing options...
woodplease Posted January 25, 2012 Author Share Posted January 25, 2012 this seems to work, thanks. can you see whats wrong with my original code though? as it worked perfectly a couple of months ago, but now just displays a blank page. could it be some sort of php configuration issue? Quote Link to comment https://forums.phpfreaks.com/topic/255755-no-data-is-being-pulled-from-database/#findComment-1311064 Share on other sites More sharing options...
scootstah Posted January 25, 2012 Share Posted January 25, 2012 I don't know, other than it's a very ass backwards way of getting database results. Quote Link to comment https://forums.phpfreaks.com/topic/255755-no-data-is-being-pulled-from-database/#findComment-1311068 Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2012 Share Posted January 25, 2012 Your original code would have needed to start with $t=0 to get all the row(s) or use <= for the comparison. Quote Link to comment https://forums.phpfreaks.com/topic/255755-no-data-is-being-pulled-from-database/#findComment-1311104 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.