How to display following using while loop :

<div style="background-color:orange;text-align:center">
<p>Header Section</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>

I want to display all my database in above manner, It gives Parse error

I want to fetch my database using while like :
for 1st record
<div style="background-color:orange;text-align:center">
<p>Header Section For 1st record</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>

2nd record
<div style="background-color:orange;text-align:center">
<p>Header Section For 2nd record</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>

<?php
$heading=array(0=>'Heading 1',1=>'heading 2');
for ($i=0;$row=mysql_fetch_assoc($result);$i++) {
echo '<div style="background-color:orange;text-align:center">
<p>'.$heading[$i].'</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>';
}
<?php
$heading=array(0=>'Heading 1',1=>'heading 2');
for ($i=0;$row=mysql_fetch_assoc($result);$i++) {
echo '<div style="background-color:orange;text-align:center">
<p>'.$heading[$i].'</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>';
}

I receive for yor code

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given

I receive for yor code

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given

That was because you were meant to add the rest of the code which included a mysql query. $result is assigned to $result=mysql_query('SELECT blah...

<?php
$heading=array(0=>'Heading 1',1=>'heading 2');
for ($i=0;$row=mysql_fetch_assoc($result);$i++) {
echo '<div style="background-color:orange;text-align:center">
<p>'.$heading[$i].'</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>';
}

Here is my code to fetch from database

<?php
$mysqli = new mysqli("localhost", "hrushi", "123456", "testlist");

// Create the query
$query = "SELECT sku, name, price FROM products ORDER by name";

// Send the query to MySQL
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
// Iterate through the result set
while(list($sku, $name, $price) = $result->fetch_row())
printf("(%s) %s: \$%s <br />", $sku, $name, $price);
?>

I'm not very familiar with mysqli that is with the i at the end but I will give you an example that doesn't use mysql.

<?php
$heading=array(0=>'Heading 1',1=>'heading 2');
for ($i=0;$i<count($heading);$i++) {
echo '<div style="background-color:orange;text-align:center">
<p>'.$heading[$i].'</p>
</div>
<div style="border:1px solid black">
<p>Content section</p>
</div>';
}

That should give you something to base your code on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.