Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

While loop problem

Links for php scripts

Moderators: macek, egami, gesf

While loop problem

Postby sohrabkln » Wed Oct 03, 2012 10:09 am

<?php
$i=0;
$j=5;
while($j==5)
{echo $i;
echo ",";
$i=$i+.2;
if($i==1)
{break;}
?>
output: 0,.2,.4,.8
but why
<?php
$i=0;
$j=5;
while($j==5)
{echo $i;
echo ",";
$i=$i+.2;
if($i==2)
{break;}
?>

no output?
sohrabkln
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Oct 03, 2012 9:54 am

Re: While loop problem

Postby gimmle » Tue Oct 16, 2012 3:08 am

I got an output but the funny thing is that this returns an endless loop... it never stops..
not sure why but it just doesn't.
gimmle
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Oct 16, 2012 2:43 am

Re: While loop problem

Postby MeroD » Tue Oct 16, 2012 4:51 am

<?php
$i=0;
$j=5;

do {
echo $i . ",";
$i= round($i,1) + 0.2;
if( $i==2 ){break;}
} while ( $j==5 )

?>
MeroD
New php-forum User
New php-forum User
 
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: While loop problem

Postby seandisanti » Tue Oct 16, 2012 12:22 pm

This was a double post when it was created, and the issue was discussed on the other post. it was a combination of a rounding issue and poor coding practice.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: While loop problem

Postby jinijames » Wed Nov 07, 2012 4:14 am

<?php
include 'db.php';
$i=0;
$result15=mysql_query("select c.dishes from c");
while($row=mysql_fetch_array($result15))
{
if($row['dishes']!=NULL)
{
$dish[$i]=$row['dishes'];
$i++;
}

}

//$j=0;
//while($j<$i)
$j=0;
while($j<$i)
{

$result16=mysql_query("select * from dish_box where dish_name='$dish[$j]'");
while($row=mysql_fetch_array($result16))
{
$v_id=$row['dish_id'];
echo $v_id.'<br />';
}
$j++;

}

mysql_close();
?>
jinijames
New php-forum User
New php-forum User
 
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.