Joey Morani
Joey Morani

Reputation: 26581

How to display other values, when a query is limited by 3?

Can anyone tell me how to display the other values, when a query is limited my 3. In this question I asked how to order and limit values, but now I want to show the others in another query. How would I go about doing this?
Here's the code I used before:

$query  = "SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
}

Upvotes: 0

Views: 308

Answers (4)

Karthik
Karthik

Reputation: 3271

If display all rows use like this :

$query  = "SELECT gmd FROM account ORDER BY gmd DESC";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
}

If display all rows without that 3 rows use like this :

$query  = "SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3,1000000";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
}

Upvotes: 2

eyescream
eyescream

Reputation: 19612

SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3,10

Will skip first 3 values and display next 10 ones satisfying the condition. This is MySQL only solution though.

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157839

 SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3,9999999999

or may be you need pagination

Upvotes: 1

knittl
knittl

Reputation: 265161

if you LIMIT the resultset in the query you only get 3 rows returned.

if you want to show the rest, don't limit inside the query, but check the rowcount in your php loop

Upvotes: 1

Related Questions