#26411 [Fbk]: while {} else {}
| From: | helly@php.net | Date: | Wed, 26 Nov 2003 22:21:53 +0000 |
| Subject: | #26411 [Fbk]: while {} else {} | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-51125@lists.php.net to get a copy of this message | ||
ID: 26411
Updated by: helly@php.net
Reported By: php at bellytime dot com
Status: Feedback
Bug Type: Feature/Change Request
-Operating System: FreeBSD
+Operating System: *
-PHP Version: Irrelevant
+PHP Version: *
New Comment:
Read again. Your code would always print 'No results found' while the
intended change wouldn't.
Previous Comments:
------------------------------------------------------------------------
[2003-11-25 19:16:51] elmicha@php.net
Can you give a better example to support your request? Your example can
easily be written as:
while ($row = mysql_fetch_assoc($result)) {
print 'Here is a result';
...
}
if (!row) {
print 'No results found';
}
I don't think that this one test is so expensive that it makes it worth
the trouble (and cost) to clutter up the language.
------------------------------------------------------------------------
[2003-11-25 12:28:30] php at bellytime dot com
Description:
------------
How about a while...else structure. Often we do
if (!mysql_num_rows($result)) {
print 'No results found';
}
while ($row = mysql_fetch_assoc($result)) {
print 'Here is a result';
...
}
Wouldn't it be nicer to do a
while ($row = mysql_fetch_assoc($result)) {
print 'Here is a result';
...
} else {
print 'No results found';
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26411&edit=1