Welcome Guest, Not a member yet? Register   Sign In
printing specific row from array
#1

[eluser]woony[/eluser]
Hi,

I can't seem to find how i have to do this...

i get a list of items from my db. I know the ids and the value is a url.

print_r($data['banners']) gives

Array ( [0] => stdClass Object ( [bannerID] => 1 [imageUrl] => banner_11.jpg ) [1] => stdClass Object ( [bannerID] => 2 [imageUrl] => banner_2.jpg ) [2] => stdClass Object ( [bannerID] => 3 [imageUrl] => banner_3.jpg ) [3] => stdClass Object ( [bannerID] => 4 [imageUrl] => banner_4.jpg ) [4] => stdClass Object ( [bannerID] => 5 [imageUrl] => banner_5.jpg ) )

this holds the image names of my banners on my website. Now
at position of banner 1 i would like to do something like

<img src="&lt;?php echo $banners['1']['imageUrl']; ?&gt;" />

but.. that doesn't work :-) how do I get specific item from the generated arrays without having to loop through the list?
#2

[eluser]woony[/eluser]
Ok..

i just found out CI makes objects of them in the array. I just made an object of the specific row first...

somewhat like this

&lt;?php
$banner1 = $banners[0];

?&gt;
<div id="promo"><img border="0">imageUrl?&gt;" /></div>

if there is a better solution for this. please do tell.
#3

[eluser]danmontgomery[/eluser]
Code:
echo $banners[4]->imageUrl;
#4

[eluser]woony[/eluser]
[quote author="noctrum" date="1278958662"]
Code:
echo $banners[4]->imageUrl;
[/quote]

thank you, figured out the whole "array of objects" now :-) just started working with a framework so :-)




Theme © iAndrew 2016 - Forum software by © MyBB