Simple question-how to display contents of an array.
Posted: Wed Jun 23, 2010 4:33 pm
I have code that retrieves information from a mySql database and puts it into an array. I want to know if it's actually pulling the information into my array by creating a code (maybe using foreach?) that will display all of the values in the array. Very new to sql and using someone else's code, but thinking this should be simple for any experienced php programmer.
Here's what I think is the relevant code:
The query is just what I got from the query in my database. This is all then put into a variable:
I didn't include the part of the GetBlogPosts() function that contains the query because I didn't think it was useful. Then again, very new to php (day 2).Let me know if you need any more information.
So, any help on how to check to see what's in my $blogPosts would be awesome, particularly if you can tell me how to display the full contents so I can do this with problems in the future too. Thanks so much for taking the time to help!
Here's what I think is the relevant code:
Code: Select all
$postArray = array();
while ($row = mysql_fetch_assoc($query))
{
$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row["author_id"], $row['dateposted']);
array_push($postArray, $myPost);
}
return $postArray;
Code: Select all
$blogPosts = GetBlogPosts();
So, any help on how to check to see what's in my $blogPosts would be awesome, particularly if you can tell me how to display the full contents so I can do this with problems in the future too. Thanks so much for taking the time to help!