Jump to content

Recommended Posts

I am trying to pull some data from the database but I want the output to be the first row of data in a <div> then the second row of data in the next <div>

Then I want the 3rd and 4rth rows each in their own <div> but be able to have <div> 3 and 4 clear the first two <div>  Basically creating a table like layout with two columns.  Here is what I have so far for the output.  I'm not sure what code I need to make it work.

 

$result = mysqli_query($link, 'SELECT * From elders order by orderby');
if (!$result)
{
$error = 'Error getting elders: ' . mysqli_error($link);
include  '/includes/error.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
if (($row['avail']) =='Y')
{
                echo '<div style="clear:both">';
	echo '<div class="elderblock">';
	echo '<img src = "http://www.bbcpa.org/images/' . ($row['image']) . '" alt="' . ($row['LastName']) . ' elders photo" class="elderimg" />';
	echo ($row['HFirst']) . " " . ($row['WFirst']) . " " . ($row['LastName']) . '<br />';
	echo ($row['position']) . '<br />';
	echo ($row['email']) . '<br />';
	echo ($row['email2']) . '<br />';
	echo '<div style="clear:both">';
	echo '<span class="elderbio">' . ($row['bio']) . '</span>';
	echo '</div>';
	echo '</div>';

        echo '<div class="elderblock">';
	echo '<img src = "http://www.bbcpa.org/images/' . ($row['image']) . '" alt="' . ($row['LastName']) . ' elders photo" class="elderimg" />';
	echo ($row['HFirst']) . " " . ($row['WFirst']) . " " . ($row['LastName']) . '<br />';
	echo ($row['position']) . '<br />';
	echo ($row['email']) . '<br />';
	echo ($row['email2']) . '<br />';
	echo '<div style="clear:both">';
	echo '<span class="elderbio">' . ($row['bio']) . '</span>';
	echo '</div>';
	echo '</div>';
                echo '</div>';
}
  }

 

The class=elderblock sets the width of the div and floats it left.  I get the layout to look correct but it is repeating the 1st row from the database 2 times.  So the same data is output side by side then the next row has the next line from the database 2x and so on.  I'm not sure how to make it pull only the info 1 time then move to the next row in the database and placing the info in the next div.

 

I hope this makes sense.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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