SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
-
Mar 1, 2005, 19:37 #1
- Join Date
- Apr 2003
- Location
- PA
- Posts
- 518
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Quick Question: "False" assignments
PHP Code:while ( $category_array[] = $db->sql_fetchrow($result) );
Why is it that when $db->sql_fetchrow() returns FALSE, it is stored in my category array? Shouldn't it stop when it returns false?
-
Mar 1, 2005, 19:51 #2
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nope, php is doing exactly what you ask:
evaluate $db->sql_fetchrow($result)
store the result as the last element of $category_array
check that same value, if false (or null or empty string or 0) continue on past the while loopJason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
-
Mar 1, 2005, 19:52 #3
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It stops when the whole expression $category_array[] = $db->sql_fetchrow($result) evaluates to false; by this time false has already been added to your array.
DouglasHello World
-
Mar 1, 2005, 19:57 #4
- Join Date
- Apr 2003
- Location
- PA
- Posts
- 518
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah... okay. Darn, thats a doosey.
-
Mar 1, 2005, 20:12 #5
- Join Date
- Aug 2004
- Location
- California
- Posts
- 1,672
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Wasn't there a thread a while back about some of the time travel functions in PHP? Perhaps one of these could be used to alter the execution of the script between the fetch and the assignment.
Christopher
-
Mar 4, 2005, 19:15 #6
Moved to a more appropriate forum. See Where should I post my thread? for details
SeanHarry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature
-
Mar 4, 2005, 19:58 #7
- Join Date
- Dec 2003
- Location
- Albany, New York
- Posts
- 1,355
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just change it to:
PHP Code:while($row=$db->sql_fetchrow($result))
$catergory_array[]=$row;
Bookmarks