|
-
May 19th, 2009, 09:19 PM
#1
Thread Starter
Fanatic Member
Get rid in while (fetch_array)
How to get rid in the while (mysql_fetch_array) i use the exit but did not work.
In this code "exit" works.
Code:
while ($counter < 10)
{
if ($counter == 5)
{
exit;
}else
{
echo $counter
}
}
While in this code "exit" doesn't work. Cause when the codition meets it supposed to stop the while statement, but it wont stop it will continue the looping.
Code:
while ($fields = mysql_fetch_array($sql))
{
if ($fname == $fields['fname'] && $lname == $fields['lname'])
{
echo "welcome"
exit;
}
}
-
May 20th, 2009, 01:58 AM
#2
Re: Get rid in while (fetch_array)
"exit" will kill the script. the command you want to look at is "break." the other similar command is "continue." break will break out of your loop, and continue will continue on in your loop.
PHP Code:
<?php $i = 0; while($i < 200){ $i++; if($i == 5) break;
echo $i; } ?>
that code should produce the following: 1234
Last edited by kows; May 20th, 2009 at 02:01 AM.
-
May 20th, 2009, 02:45 AM
#3
Thread Starter
Fanatic Member
Re: Get rid in while (fetch_array)
No i know that i referring in how to get rid in this code
Code:
while ($fields = mysql_fetch_array($sql))
{
if ($fname == $fields['fname'] && $lname == $fields['lname'])
{
echo "welcome"
exit;
}
}
Cause in their even though its already true in the condition, the loop will continue so how to stop that
-
May 20th, 2009, 04:40 AM
#4
Re: Get rid in while (fetch_array)
the loop will not continue if the condition is true in your IF statement because "exit" tells PHP to stop processing the script. I'm not sure what you're talking about.
-
May 20th, 2009, 07:07 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|