RE: [PHP-DB] LIMIT

From: Date: Fri, 30 Jun 2000 14:00:33 +0000
Subject: RE: [PHP-DB] LIMIT
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-782@lists.php.net to get a copy of this message
It depends on exactly what you want to do with the data....for example... If you grab ALL of the data with one query (not using the LIMIT statement), then you could use mysql_num_rows to find out the total number of rows that are returned. If you then want to do different things based on what row you are on (rows 0,5 as opposed to 6,10 or 10,15), then you could setup a counter before you loop through your result set. Kind of like: <code> //Setup your SQL string and execute it against the database $sqlstr = "My SQL String" ; $result = mysql("database_name", $sqlstr, $your_link_identifier) ; // Get the number of rows returned $row_count = mysql_num_rows($result) ; //Initialize your counter and loop through your result set $counter = 0 ; while ($my_array = mysql_fetch_array($result)) { if ($counter >= 0 && $counter < 5) { // Do whatever you want for the first 5 rows returned } elseif ($counter >=5 && $counter < 10) { // Do whatever you want for rows 6 through 10 } ... ... ... $counter++ ; } </code> Sam Masiello System Analyst Chek.Com (716) 853-1362 x289 smasiello@chekinc.com -----Original Message----- From: Torsten Curdt [mailto:tcurdt@dff.st] Sent: Friday, June 30, 2000 3:59 AM To: Sam Masiello; php-db@lists.php.net Subject: RE: [PHP-DB] LIMIT > If you remove the LIMIT 0,5 from your query you will get all of > the rows by > using mysql_num_rows. Since you have LIMIT 0,5 on their now, 5 rows are > returned from the query, thus there are 5 rows in your result set (hence, > the 5 returned from mysql_num_rows). Do I really need to make two queries to obtain the number of rows for SELECT * FROM tblArtikel ORDER BY artID maxrows = mysql_num_rows to know when to stop when iterating with SELECT * FROM tblArtikel ORDER BY artID LIMIT 0,5 SELECT * FROM tblArtikel ORDER BY artID LIMIT 5,5 SELECT * FROM tblArtikel ORDER BY artID LIMIT 10,5 ... -- Torsten

« previous php.db (#782) next »