$desquery = "SELECT DISTINCT destination FROM stuff";
$des = mysql_query($desquery) or die(mysql_error());
while($datarow = mysql_fetch_row($des)){
for ($i=0;$i <count($datarow);$i++)
{
if ($i==3) {echo "Hello";}
echo $datarow[$i];
echo "</br>";
echo $i;
echo "</br>";
}}
Give output
Singapore
0
Haipong
0
sin
0
shanghai
0
hongkong
0
sidney
0
BANGKOK
0
My question why $i output not increase (always 0) so that the “hello” word never printed. Thx for help
You are selecting only one column, so
count($datarow)is every time exactly 1. Thewhileloop loops over every row selected from database and theforcycle is trying to loop over selected columns, which is always 1 on every row, so$iis never increased and every time reinitialized to0.