Is this a bug in PHP? While Loop problem?

ardy1234567

New member
Ok I know what I am doing and I certainly know the expected output. I am going through with this for 3 days now and I dont know what is wrong. It is supposed to work.

Note the echos there I put for debugging reasons.

assume:
$SI_Info_Size=2
$SI_Info=(4008096626,400810200)
$result=returns 1 row with 1 column

for ($i=0; $i < $SI_Info_Size;$i++)
{
$row_boqs=$SI_Info[$i];
echo $row_boqs. " "; //for debugging
while ($row=mysql_fetch_array($result))
{
echo $row_boqs. " "; //for debugging
}
}

Output:
1st echo:
4008096626 400810200

2nd echo:
(empty or null)

Ok that is the problem with while looping I even simulate even simpler conditions like while $i =1
same thing happens. I dont know whats wrong. Even other variables contained in the scope of While Loop ends up empty if you use it outside it. Please help what am I missing here?. $row_boqs should have the same value.They are all empty when they are used within a While Loop.Any variable within it are empty.
sometimes it will work but it outputs only the first element in $SI_Info. The while loop is inside the for loop so it should be repeated two times. and $row_boqs is changed as the $i changes so it should have an output of the two elements in the array. Like this

Expected results:
1st echo
4008096626 400810200
2nd echo
4008096626 400810200

usual results
1st echo
4008096626 400810200
2nd echo

occasional results
1st echo
4008096626 400810200
2nd echo
4008096626

as you can see in some situations when I use while looping it does work but for arrays it only gets the first element even when there is an increment involved in the array.

for example:
$i=1
inside while loop
{
$SI_Info[$i] //output should be 400810200 instead the output would be 4008096626
}

however forcing it to be static works
$i=1
inside while loop
{
$SI_Info[1] //output is 400810200
}

What's going on with this While Looping? This does not happen on other languages

I am stuck with this while looping and it is the only trick to fetch the arrays correctly. But having incorrect vslues in its scope wont get me anywhere.
ok here is the query something similar to that

students table
name id
johnson 23
raphael 24

select id from students where id=24

with that kind of simple query I doubt there is a problem over there. I tested that kind of while looping not involving the database or my sql. just a simple php script.

Same thing happens on variables set outside the while looping is unaccessible or nulled if you access it within the while looping. That's a pain.
 
Back
Top