views:

44

answers:

4

Hello. 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))
{
}

Thanks!

+1  A: 

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

knittl
+2  A: 

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))
{
}
Karthik
Also consider these common constructs (skipping the `ORDER BY` clause for simplicity):1) `sprintf("SELECT gmd FROM account LIMIT %d,%d", $s, $n)` to display `n` elements starting from `s`; or:2) `sprintf("SELECT gmd FROM account LIMIT %d,%d", ($p-1)*$n, $n)` to display "page `p` of results", with `n` results per page (and page numbering starting at 1). This is a *very* common construct, used for general-case result pagination.
herenvardo
+1  A: 
 SELECT gmd FROM account ORDER BY gmd DESC LIMIT 3,9999999999

or may be you need pagination

Col. Shrapnel
+1  A: 
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.

eyescream