Jump to content

How to insert data into a div using a foreach statement.


shyam13

Recommended Posts

How do I insert data which I retrieved from the database using a select statement and then using a for each loop insert the data into separate divs,

so far I have used a select statement to get the data but I am struggling to use the for each loop to insert the data into separate divs.

 

Any ideas anyone?

 

 

You need to use a while() loop. A foreach() loop is used to iterate through an array, and would only work if you only have one result to loop through.

 

$query = mysql_query("SELECT * FROM table");

while($row = mysql_fetch_assoc($query)) {
echo '<div>' . $row['column'] . '</div>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.