Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql_getrowswithoutlimit

Status
Not open for further replies.

iamsw00sh

Programmer
May 21, 2003
92
RO
This is the code

Code:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable LIMIT 0,19");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf("ID: %s  Name: %s", $row[0], $row[1]);  
}

mysql_free_result($result);
?>

The question is:

Is there a way to find out the total number of recdords?
i mean this query is returning 20 records because of the LIMIT ...
let's say there are 23 records in the table ...
is there some mysql_something or mysql_getrowswithoutlimit ? :)

or i need to run the query twice to find out how much more records are in there?

thank you

--
If I would be such a good coder as I like coding ... I would be the Best
 
AFAIK no. With your query you define what you want to display and when php receives information from mysql that executed query is all it has to work with. If you want to avoid accessing database twice, you might try limiting the query via php. That might be better idea if there are 23 records and you're showing 20 but worse if there are 800 records...
 
i don't think it is impossible. try modifying the query as follows:

Code:
$sql="
   SELECT count(*) as cnt, id, name 
   FROM mytable 
   GROUP BY id, name
   LIMIT 0,19
   ";

each row will then have a column called cnt containing the total number of rows. the important thing is that you need to use the group by syntax with functions like count max or min.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top