PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
arya6000
Forum Newbie
Posts: 15 Joined: Fri Apr 07, 2006 3:32 pm
Post
by arya6000 » Thu Feb 05, 2009 8:43 pm
Hi
I'm a C programmer and I'm learning php now, I wrote a program something like
Code: Select all
while($row = mysql_fetch_array($result) && $i < 250)
{
....
.....
}
But it does not work. I tried to find some reference online for using && and || in php loops and I did not find anything. Does php support && and || in loops?
Thank You
Last edited by
arya6000 on Thu Feb 05, 2009 9:13 pm, edited 1 time in total.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Thu Feb 05, 2009 8:55 pm
Indeed PHP does support both. More info can be found on the
operators page, and more specifically the
logical operators page.
PHP also supports AND and OR, although they hold different precedence.
Can you define "does not work"?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Thu Feb 05, 2009 9:06 pm
John Cartwright wrote: PHP also supports AND and OR, although they hold different precedence.
Yay! Only thing missing is a link to the
operator precedence page.
As a C programmer you should be familiar with the concept of precedence. Notice how && is higher in the table than =?
arya6000
Forum Newbie
Posts: 15 Joined: Fri Apr 07, 2006 3:32 pm
Post
by arya6000 » Thu Feb 05, 2009 9:12 pm
ok, thanks it working now.
All I needed was to put them in brackets like
while(($row = mysql_fetch_array($result)) && ($i < 250))
Skoalbasher
Forum Contributor
Posts: 147 Joined: Thu Feb 07, 2008 8:09 pm
Post
by Skoalbasher » Thu Feb 05, 2009 10:52 pm
arya6000 wrote: ok, thanks it working now.
All I needed was to put them in brackets like
while(($row = mysql_fetch_array($result)) && ($i < 250))
Doh! lol