icor1031 Posted September 17, 2014 Share Posted September 17, 2014 (edited) $results = mysqli_query($con, 'SELECT TOP 8 * FROM Entries'); var_dump($results); This gets me bool(false) ------------ $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 9"); But, this gets me the proper results - it draws from my database, like it should. Why do I get false, when I use TOP 8? Thanks. Edited September 17, 2014 by icor1031 Quote Link to comment Share on other sites More sharing options...
trq Posted September 17, 2014 Share Posted September 17, 2014 TOP is not valid syntax in MySQL. Quote Link to comment Share on other sites More sharing options...
icor1031 Posted September 17, 2014 Author Share Posted September 17, 2014 (edited) Woops, I misunderstood this: http://www.w3schools.com/sql/sql_top.asp I've been using limit, but the problem is that it doesn't call the most recent entry - even if I use LIMIT 0,8. And LIMIT -1,8 gives an error. Should I find the PID, then +1 it? Any advice? Thanks! Edited September 17, 2014 by icor1031 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 17, 2014 Share Posted September 17, 2014 you should probably post an example of the incorrect data the query is matching and an example of the data the query should match, along with the table definition. if your order by isn't returning the correct value, it's likely that your table definition is storing numbers as a character/text type. Quote Link to comment Share on other sites More sharing options...
icor1031 Posted September 17, 2014 Author Share Posted September 17, 2014 (edited) I "fixed" it, by adding the third line. I'm not satisfied with that result, but it works. For some reason, the while statement started one item too late. $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 0,8"); $rowFp = mysqli_fetch_array($results); echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; while ($rowFp = mysqli_fetch_array($results)) { echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; Here, you see my last PID: Here, you see that my PID began (before my "fix") one number higher than what exists in the database: Column stuff: Edited September 17, 2014 by icor1031 Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted September 17, 2014 Solution Share Posted September 17, 2014 (edited) Delete lines 2 and 3. Just fetch and output with the while() loop. $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 0,8"); while ($rowFp = mysqli_fetch_array($results)) { echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; } Edited September 17, 2014 by Barand Quote Link to comment Share on other sites More sharing options...
icor1031 Posted September 17, 2014 Author Share Posted September 17, 2014 Delete lines 2 and 3. Just fetch and output with the while() loop. $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 0,8"); while ($rowFp = mysqli_fetch_array($results)) { echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; } Awesome, thanks. 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.