Php/mysql Array Help Need
Solution 1:
You mean while($j<$i)
there.
Remember, you incremented $i after the last insert. This means that $i will be higher than the maximum key of $dish.
Some thoughts:
Any time you're testing for equality with null, you should consider using is_null
(or !is_null). It is more accurate.
This:
$dish[$i]=$row['dishes'];
$i++;
Would be better as:
// obviously instead of $i you would use count($dish) later (oruseforeach)
$dish[]=$row['dishes'];
That final while loop would be better as a foreach:
foreach($dishas$val)
{
echo$val;
}
Solution 2:
You need to make sure the index exists before echoing it, as so:
while($j<=$i)
{
if (isset($dish[$j])) echo$dish[$j];
$j++;
}
Solution 3:
Your second while loop is going to far. You only define dishes up to i-1
and then you loop through it up to and including i
. Change it to:
while($j<$i)
Post a Comment for "Php/mysql Array Help Need"