php loop update
Posted: Fri Dec 10, 2010 7:10 pm
I'm trying to loop through the rows once and update the rows to the new corresponding values, but the script seems to be looping and updating the rows for the amount of entries are in that table. Been racking my brain, but just can't figure out where I've gone wrong. -.-
Any help would be greatly appreciated!
Any help would be greatly appreciated!
Code: Select all
$sql="SELECT * FROM royals";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
while($rows=mysql_fetch_array($result))
{
$id[]=$rows['id'];
echo "".$rows['nickname']." (id=".$rows['id'].") (potentiallength=".$rows['potentiallength'].") (length=".$rows['length'].") <br>";
if ($descript3['lifestage'] < 3)//if age is under adolescent add 1/12th of 40% of the growth left in inches if fed well per month
{
$potentiallength = $rows['potentiallength'];
$growthleft = ($potentiallength-16);
$growth = (($growthleft*.40)/12);
echo "(growth=".$growth. ")";
for($i=0;$i<$count;$i++){
$sql1="UPDATE royals SET length=length+1 WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
}//end for
}