Re: [PHP] PHP and Mysql Limit
On Wed, 2 Jul 2003, Jeff Harris wrote: > Then, once you've done it enough times, $start = $count = 178. > [code] > while ($start <= $count) { > // when $start = $count = 178, you won't retrive any data > [/code] The recordset would not alway contain an even number of records resulting in 10 records per page. It may contain something like 1027 records which should then produce 103 pages. 102 pages each with 10 records and one page of only 7 records. Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP and Mysql Limit
Yes, the next page of results would start at #18. The page number only increments by 1. Ed On Wed, 2 Jul 2003, Chris Sherwood wrote: > It looks like your adding 10 to 8 thus getting 18... of course I maybe > looking at this wrong > > - Original Message - > From: <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Wednesday, July 02, 2003 9:23 AM > Subject: [PHP] PHP and Mysql Limit > > > > > > I've created a script that reads a sorted mysql query and outputs specific > > results into text files defined by the start and limit of mysql. The > > database holds 178 records. I want to start my output on #9 with 10 > > records per page. Should leave me with 17 equal pages right? > > > > $count = 178 > > $start = 8; (Mysql starts at record 0) > > $per_page = 10; > > $page = 1; > > > > while ($start <= $count) { > > > > $fp = fopen("Page$page.txt", "w"); > > > > mysql_connect ($host, $user, $pass); > > > > mysql_select_db ($database); > > > > $result = mysql_query ("SELECT * FROM internal_listings, agents WHERE > > internal_listings.agent = agents.name AND category = 'Standard' ORDER by > > area,price LIMIT $start, $per_page"); > > > > if ($row = mysql_fetch_array($result)) { > > > > do { > > > > ##misc ouput to file $fp for 10 records in query > > > > } > > > > while($row = mysql_fetch_array($result)); > > > > } > > > > fclose($fp); > > > > mysql_close(); > > > > $start = $start + $per_page; > > > > $page++; > > > > } > > > > > > When I run the script outlined above I get 18 pages. Page number 18 is > > blank as it should be as there should be no more listings to output to a > > text file but why is there a page number 18 to begin with? It should end > > with page number 17. > > > > Thanks in advance for any insight, > > > > Ed > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP and Mysql Limit
|- Original Message - |From: <[EMAIL PROTECTED]> |To: <[EMAIL PROTECTED]> |Sent: Wednesday, July 02, 2003 9:23 AM |Subject: [PHP] PHP and Mysql Limit | | |> |> I've created a script that reads a sorted mysql query and outputs specific |> results into text files defined by the start and limit of mysql. The |> database holds 178 records. I want to start my output on #9 with 10 |> records per page. Should leave me with 17 equal pages right? |> |> $count = 178 |> $start = 8; (Mysql starts at record 0) |> $per_page = 10; |> $page = 1; |> |> while ($start <= $count) { |> |> $fp = fopen("Page$page.txt", "w"); [snip] On Jul 2, 2003, "Chris Sherwood" claimed that: |It looks like your adding 10 to 8 thus getting 18... of course I maybe |looking at this wrong | Then, once you've done it enough times, $start = $count = 178. [code] while ($start <= $count) { // when $start = $count = 178, you won't retrive any data [/code] I would probably also move as much of the mysql_connect as possible to outside the loop. It only needs to be done once. -- Registered Linux user #304026. "lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import" Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP and Mysql Limit
It looks like your adding 10 to 8 thus getting 18... of course I maybe looking at this wrong - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, July 02, 2003 9:23 AM Subject: [PHP] PHP and Mysql Limit > > I've created a script that reads a sorted mysql query and outputs specific > results into text files defined by the start and limit of mysql. The > database holds 178 records. I want to start my output on #9 with 10 > records per page. Should leave me with 17 equal pages right? > > $count = 178 > $start = 8; (Mysql starts at record 0) > $per_page = 10; > $page = 1; > > while ($start <= $count) { > > $fp = fopen("Page$page.txt", "w"); > > mysql_connect ($host, $user, $pass); > > mysql_select_db ($database); > > $result = mysql_query ("SELECT * FROM internal_listings, agents WHERE > internal_listings.agent = agents.name AND category = 'Standard' ORDER by > area,price LIMIT $start, $per_page"); > > if ($row = mysql_fetch_array($result)) { > > do { > > ##misc ouput to file $fp for 10 records in query > > } > > while($row = mysql_fetch_array($result)); > > } > > fclose($fp); > > mysql_close(); > > $start = $start + $per_page; > > $page++; > > } > > > When I run the script outlined above I get 18 pages. Page number 18 is > blank as it should be as there should be no more listings to output to a > text file but why is there a page number 18 to begin with? It should end > with page number 17. > > Thanks in advance for any insight, > > Ed > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP and Mysql Limit
I've created a script that reads a sorted mysql query and outputs specific results into text files defined by the start and limit of mysql. The database holds 178 records. I want to start my output on #9 with 10 records per page. Should leave me with 17 equal pages right? $count = 178 $start = 8; (Mysql starts at record 0) $per_page = 10; $page = 1; while ($start <= $count) { $fp = fopen("Page$page.txt", "w"); mysql_connect ($host, $user, $pass); mysql_select_db ($database); $result = mysql_query ("SELECT * FROM internal_listings, agents WHERE internal_listings.agent = agents.name AND category = 'Standard' ORDER by area,price LIMIT $start, $per_page"); if ($row = mysql_fetch_array($result)) { do { ##misc ouput to file $fp for 10 records in query } while($row = mysql_fetch_array($result)); } fclose($fp); mysql_close(); $start = $start + $per_page; $page++; } When I run the script outlined above I get 18 pages. Page number 18 is blank as it should be as there should be no more listings to output to a text file but why is there a page number 18 to begin with? It should end with page number 17. Thanks in advance for any insight, Ed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php