0

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>

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by cwarn23
0
<?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>';
}
0
<?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

0

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...

0
<?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);
?>
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.