trq Posted October 9, 2008 Share Posted October 9, 2008 $mquery is a result resource, not an array. You need to pull a record (as an array) from this resource. eg; <?php ini_set('display_errors', 1); error_reporting(E_ALL); $query ="SELECT * FROM `news` ORDER BY `date` DESC LIMIT 5"; if ($mquery = mysql_query($query)) { if (mysql_num_rows($mquery)) { ?> <table width="10" border="1" cellspacing="0" cellpadding="0"> <tr> <th scope="row">Author Name</th> </tr> <tr> <th scope="row">Date</th> </tr> <tr> <th scope="row">Topic</th> </tr> <tr> <th scope="row">Articale</th> </tr> </table> <?php while ($data = mysql_fetch_assoc($mquery)) { //this will loop through your row data returned from the db echo "<tr bgcolor=#EEEEEE>\n"; echo "<td>{$data['authorname']}</td>\n"; echo "<td>{$data['date]'}</td>\n"; echo "<td>{$data['newstitle']}</td>\n"; echo "<td>{$data['news']}</td>\n"; echo "</tr>\n"; } } else { echo "No results found"; } } else { echo mysql_error(); } ?> </table> I also added better tests of your results. Quote Link to comment Share on other sites More sharing options...
topflight Posted October 9, 2008 Author Share Posted October 9, 2008 Now I am receiving this Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\viewnews.php on line 48 and line 48 is while($data = mysql_fetch_assoc($mquery){ //this was changed Quote Link to comment Share on other sites More sharing options...
topflight Posted October 9, 2008 Author Share Posted October 9, 2008 thorpe for your code I am now receiving this Parse error: syntax error, unexpected '}', expecting ']' in C:\xampp\htdocs\viewnews.php on line 50 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 while($data = mysql_fetch_assoc($mquery){ should be while($data = mysql_fetch_assoc($mquery)){ Quote Link to comment Share on other sites More sharing options...
topflight Posted October 9, 2008 Author Share Posted October 9, 2008 Thanks all it works I hope I did not bother you guys. PHP freaks has been a big help when it comes to learning php well I am going to start reading this book and start learning php the right way thanks all. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 No problem and good luck. Its not that hard once you get some concepts down. 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.