I’m calling from a database the information of posts in a topic. I am using mysql_fetch_assoc() to do so. I’ve got the first post working, but I don’t know how to access the replies. So I figured if I got the list of posts in that topic, I could do so.
Here is a sample of my code that I’m working on:
$result1 = mysql_query("SELECT * FROM posts WHERE topic_id='" . $topicinfo['id'] . "'");
while($row = mysql_fetch_assoc($result1)){
$postinfo = print_r($row);
}
$topicinfo[] is an array of info on the topic.
The problem with this code is that I would like to save the results in a variable, not just automatically printing it out.
Is this possible?
What you want to do is push all of the results you extract from the database into an array.
Now the array
$postswill contain all the results from the database. The syntax[]is simply shorthand forarray_push()