futrose Posted June 5, 2011 Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238429-pulling-information-from-database-in-a-loop/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.