Forum Moderators: coopster

Message Too Old, No Replies

do..while adding result in first spot

         

dkin

3:39 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



I am trying to match numbers with results ie first

1 result
2 result
3 result

etc

but my do while loop

$counter = "0";
do
{
++$counter;
print ''.$counter.'<a href="?url=singlepic&id='.$myrow[pic_id].'"><img alt="'.$myrow[pic_id].'" src="upload/thumb/th_'.$myrow[pic_id].'.jpg" /></a><br><br>';
}
while ($myrow = mysql_fetch_array($results));

is giving me a blank #1 from the database from some reason, I have the limit set to 10 but it is posting 11, 1 blank and then the 10 I want.

Anyone know how to solve this?

mcibor

3:55 pm on Dec 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The statement in while() is true 10 times, so you are doing:
first go do --> while true (1st time)
do --> while true (2nd time)
do --> while true (3rd time)
do --> while true (4th time)
do --> while true (5th time)
do --> while true (6th time)
do --> while true (7th time)
do --> while true (8th time)
do --> while true (9th time)
do --> while true (10th time)
do --> while false end loop

Altogether you are doing the loop 11 times. The answer to your problem may be discarding the do..while loop and using only while() {} loop. It should solve the problem.

$counter = "0";
while ($myrow = mysql_fetch_array($results))
{
++$counter;
print ''.$counter.'<a href="?url=singlepic&id='.$myrow[pic_id].'"><img alt="'.$myrow[pic_id].'" src="upload/thumb/th_'.$myrow[pic_id].'.jpg" /></a><br><br>';
}

Happy New Year from
Michal Cibor

dkin

4:33 pm on Dec 29, 2004 (gmt 0)

10+ Year Member



thats the ticket, thanks alot.