RE: [PHP-DB] Select a subset?
> From: Clive Bruton [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, July 16, 2002 10:24 PM > > Joakim, thanks, that sorted it. Just one note, "numrows" in > the sql query > should be "num_rows"? That's how I got it to work anyway. Yes, that's totally correct. Just a typo. Joakim -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Select a subset?
[EMAIL PROTECTED] wrote at 16/07/02 09:44 > $result = mysql_query("SELECT COUNT(*) as numrows FROM >table",$db); > $row = mysql_fetch_array($result); > $num_rows = $row['num_rows']; Joakim, thanks, that sorted it. Just one note, "numrows" in the sql query should be "num_rows"? That's how I got it to work anyway. -- Clive -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Select a subset?
> From: Clive Bruton [mailto:[EMAIL PROTECTED]] > Sent: Monday, July 15, 2002 5:01 PM > > How do I get both the number of rows found (5,000) and get a > subset of > the records (ie 0-9, 10-19, 20-29...) so that a user can > browse through > the records rather than getting 5,000 at a time (but still > know that a > total of 5,000 were found). I think you need to do two querys. At least that's how I do it... First SELECT COUNT(*) FROM table and then SELECT whatever FROM table LIMIT 0,10 list.php: "; echo "NamePosition\n"; while ($myrow = mysql_fetch_row($result)) { printf("%s %s%s\n", $myrow[1], $myrow[2], $myrow[3]); } echo "\n"; ?> Previous Next This oughta do it... Regards Joakim Andersson -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select a subset?
Adam Alkins wrote at 15/07/02 04:06 >mysql_num_rows just counts the amount of rows in a query, so if you only >selected 10 rows, it will return 10. > >If you want to count all the rows in the table, its best to use the COUNT() >function > > SELECT COUNT(*) FROM table In my example, I've selected all rows, ie no search criteria. But let's assume that I have in fact searched for something that returns half the records in the table (5,000 rows). How do I get both the number of rows found (5,000) and get a subset of the records (ie 0-9, 10-19, 20-29...) so that a user can browse through the records rather than getting 5,000 at a time (but still know that a total of 5,000 were found). I hope this makes sense. -- Clive -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Select a subset?
I think the paging function is what you want SELECT * from table limit 0,10 for the first ten records SELECT * from table limit 11,20 for the next ten, etc. Gary Every Sr. UNIX Administrator Ingram Entertainment (615) 287-4876 "Pay It Forward" mailto:[EMAIL PROTECTED] http://accessingram.com -Original Message- From: Clive Bruton [mailto:[EMAIL PROTECTED]] Sent: Sunday, July 14, 2002 2:50 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Select a subset? I'm just starting to play with PHP and MySQL, kind of getting my head around it, but one thing I'm not getting (right) is delivery of a subset of the found records from MySQL. ie if 100 are found how do I get records 1-10 (or 11-20...). What I have so far is: ... "; echo "NamePosition\n"; while ($myrow = mysql_fetch_row($result)) { printf("%s %s%s\n", $myrow[1], $myrow[2], $myrow[3]); } echo "\n"; ?> However, this delivers all 10,000+ rows on one HTML page. I have worked out how to use "LIMIT" as an SQL command: $result = mysql_query("SELECT * FROM url LIMIT 10, 10",$db); ie start at record 10 and show the next 10. But this delivers back "10" as the $num_rows variable, when I want the total number of rows. I don't really have to complete two querys to get the appropriate values do I? I'm running PHP 4.2.1 on MacOS X 10.1.4. TIA -- Clive -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Select a subset?
> ie start at record 10 and show the next 10. But this delivers back "10" > as the $num_rows variable, when I want the total number of rows. > > I don't really have to complete two querys to get the appropriate values > do I? mysql_num_rows just counts the amount of rows in a query, so if you only selected 10 rows, it will return 10. If you want to count all the rows in the table, its best to use the COUNT() function SELECT COUNT(*) FROM table -- Adam Alkins http://www.rasadam.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Select a subset?
I'm just starting to play with PHP and MySQL, kind of getting my head around it, but one thing I'm not getting (right) is delivery of a subset of the found records from MySQL. ie if 100 are found how do I get records 1-10 (or 11-20...). What I have so far is: ... "; echo "NamePosition\n"; while ($myrow = mysql_fetch_row($result)) { printf("%s %s%s\n", $myrow[1], $myrow[2], $myrow[3]); } echo "\n"; ?> However, this delivers all 10,000+ rows on one HTML page. I have worked out how to use "LIMIT" as an SQL command: $result = mysql_query("SELECT * FROM url LIMIT 10, 10",$db); ie start at record 10 and show the next 10. But this delivers back "10" as the $num_rows variable, when I want the total number of rows. I don't really have to complete two querys to get the appropriate values do I? I'm running PHP 4.2.1 on MacOS X 10.1.4. TIA -- Clive -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php