0

Ok, it seems this would not be so hard, but for some reason it is not liking me today.

so basically the array returns like this

Array ( [0] => Array ( [id] => 2 [title] => this test [content] => this is a test [releasedate] => 2011-07-23 16:19:59 [publish] => 1 ) [1] => Array ( [id] => 1 [title] => 'title2' [content] => 'This is story 2'. [releasedate] => 2011-07-23 15:34:25 [publish] => 1 ) )

however it seems not to show when I do the following

foreach( $res as $story){
    print $story->title;
}
1
  • Associated array is not an object class in php, you can't use -> .only if you have an array of objects you can use -> Commented Jul 23, 2011 at 6:27

1 Answer 1

2

This is an associative array, so do print $story['title']

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, that works great, but how do I only allow it to show 1 of the story["title"] I thought by $story[0]["title"] but that does not seem to work, is there an $i thing I need to do?
$res[0]['title'] instead of $story[0]['title']
sadly that just prints the same title out twice
basiclly I want to be able to tell the server what to do with each title, (I am making a news site)
for that you have not to print it out in foreach loop, just do print $res[0]['title'] without array iteration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.