Jump to content

PHP - SQL: TOP


icor1031
Go to solution Solved by Barand,

Recommended Posts

    $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 by icor1031
Link to comment
Share on other sites

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:

 

Ef8mKIq.png

 

 

Here, you see that my PID began (before my "fix") one number higher than what exists in the database:

 

JqzTK7w.png

 

 

 

Column stuff:

7Iw9ur6.png

Edited by icor1031
Link to comment
Share on other sites

  • Solution

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 by Barand
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.