I am trying to get posts from my mybb database, and then display it in the homepage. I wish to sort it by newest thread first, however when I attempt it it fails with this message:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/ interitu/public_html/index.php

Code used:

    <?php
$con = mysql_connect("","","");
// I HAVE REMOVED THE CONNECTION DETAILS FOR DATABASE SECURITY
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("interitu_forums", $con);

$result = mysql_query("SELECT * FROM mybb_posts ORDER BY tid ASC WHERE fid='4' LIMIT 
5");

while($row = mysql_fetch_array($result))
{

And the code goes on to stuff not relevant (HTML content).

share|improve this question
feedback

2 Answers

up vote 0 down vote accepted

order of executing sql : select, from, where, Group by, having, order by, limit. select * from FROM mybb_posts
WHERE fid='4'
ORDER BY tid ASC 
LIMIT 5


share|improve this answer
feedback
SELECT * 
FROM mybb_posts
WHERE fid='4'
ORDER BY tid ASC  
LIMIT 5

The where clause needs to be before the order by clause.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.