hi i am trying to make a slide gallery with a multidimensional array but am finding it difficult to index it. am using for loop. i keep getting an undefined offset error message. here is my code.
Try this to see what values and format is returned:
<?php
//
//I prefer using plural because there maybe more than one
$images=$db->getRows($query,$params);
var_dump($images);
// Edit:
// I prefer using this for loop
for($i=0;$i<$count;$i++) {
echo '<br>' .$i .' : ' .$count;
}
In your loop you overwrite the varialble $slides on each loop so you will only get the last image.
Are you sure you did not intend the appeand the variable, either as an array ($slides[]) or string ($slides .=)?
Incorrect. The ++$item iterator is always applied after the loop. People seem to be using ++$item instead of $item++ now because of some micro performance gain. I don’t see why we’d need to optimize on this level, but ok.
What will go wrong is $i<=$count, that should be $i < $count, otherwise for an array with 3 elements you will loop elements 0, 1, 2 and 3, but there is no element 3 (so: Notice: undefined index).