RE: [PHP-DB] How to limit a WHILE statement?
Yes, LIMIT will do the job, but to answer your question: $x = 0; while ( ( $myrow = mysql_fetch_array( $result ) ) and ( ++$x < 20 ) ) { [...] } Greetinx, Mike Michael Rudel - Web-Development, Systemadministration - ___ Suchtreffer AG Bleicherstraße 20 D-78467 Konstanz Germany fon: +49-(0)7531-89207-17 fax: +49-(0)7531-89207-13 e-mail: mailto:[EMAIL PROTECTED] internet: http://www.suchtreffer.de ___ > -Original Message- > From: Bob Stone [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, April 03, 2001 12:53 AM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] How to limit a WHILE statement? > > > Dear PHP Helpers, > > What is your recommendation on limiting a while > statement so that it only iterates a maximum of 20 > times? > > Here is the code snippet: > > $result = mysql_query($sql, $db); > > while ($myrow = mysql_fetch_array($result)) { > > printf("Name: %s > %s %s %s\n", $myrow["salutation"], > $myrow["first_name"], $myrow["mid_name"], > $myrow["user_name"]); > > Best regards, > > Bob Stone > > __ > Do You Yahoo!? > Get email at your own domain with Yahoo! Mail. > http://personal.mail.yahoo.com/?.refer=text > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] How to limit a WHILE statement?
Your might want to consider limiting the records selected. For example "select emp_name from employees limit 0,20". Alternatively consider using a a "for" statement. - Brian Hardwick Tangible Networks. -Original Message- From: Bob Stone [mailto:[EMAIL PROTECTED]] Sent: Monday, April 02, 2001 6:53 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] How to limit a WHILE statement? Dear PHP Helpers, What is your recommendation on limiting a while statement so that it only iterates a maximum of 20 times? Here is the code snippet: $result = mysql_query($sql, $db); while ($myrow = mysql_fetch_array($result)) { printf("Name: %s %s %s %s\n", $myrow["salutation"], $myrow["first_name"], $myrow["mid_name"], $myrow["user_name"]); Best regards, Bob Stone __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/?.refer=text -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] How to limit a WHILE statement?
Ok, in your $sql var, put: $sql = "SELECT * FROM table LIMIT 20"; Leave the other code intact. This fetches 20 rows from MySQL. -- David Balatero -Original Message- From: Bob Stone [mailto:[EMAIL PROTECTED]] Sent: Monday, April 02, 2001 3:53 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] How to limit a WHILE statement? Dear PHP Helpers, What is your recommendation on limiting a while statement so that it only iterates a maximum of 20 times? Here is the code snippet: $result = mysql_query($sql, $db); while ($myrow = mysql_fetch_array($result)) { printf("Name: %s %s %s %s\n", $myrow["salutation"], $myrow["first_name"], $myrow["mid_name"], $myrow["user_name"]); Best regards, Bob Stone __ Do You Yahoo!? Get email at your own domain with Yahoo! Mail. http://personal.mail.yahoo.com/?.refer=text -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]