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;
}
}
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
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
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.
Re: Get rid in while (fetch_array)
Do what kows said: put break instead of exit.