$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[i];
$i++;
}
It is printing same value.
$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[i];
$i++;
}
It is printing same value.
You are using i
for the array index instead of $i
:
$child[i]
This should be $child[$i]
. Because the i
in $child[i]
is interpreted as a constant (value of constant i
is used as index) or if there is no such constant as string. You can get a variable/value dump with var_dump
.
$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[$i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[$i];
$i++;
}
You weren't calling $i, but "i"
If you want numeric indexes you can do without $i .. try ..
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[] = $row['userId'];
}
for($i=0;$i<5;$i++)
{
echo $child[$i].' <br />;
}
Hope it helps.