FridayRain Posted September 9, 2007 Share Posted September 9, 2007 I have a blog on my main page, and the query returns the three most recent entries. What I'm trying to do is to return each entry inside a div with a different background color. I know my code isn't formatting very well, but before my website goes live, I'm going to clean up everything. Here's the full code in question. Look a few lines below the WHILE loop for the faulty div tag location: <div id="blogtext"> <?php require("db/config.php"); require("db/opendb.php"); $query = "SELECT * FROM blog ORDER BY date DESC LIMIT 3"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $date = $row[date]; echo "<div class=\"blogentry\">"; $entriesti = "<h2>$row[title]</h2>"; $entrieste = nl2br("<p>$row[text]</p><br /><br />"); echo $entriesti; echo "<div class=\"umbrella\">"; // echo "<div class=\"posterpic\"><img src=\"author.jpg\"></div>"; echo "<div class=\"datetimeposted\">"; echo "<p class=\"blogdate\">"; echo date('F d, Y', strtotime($date)); echo "</p>"; echo "<p class=\"post\">by <a href=\"greg.php\">Greg</a> at "; echo "<span class=\"blogtime\">"; echo date('h:ia', strtotime($date)); echo "</span></p>"; echo "</div>"; echo "</div>"; include("authconfig.php"); $cookuser = $_COOKIE["cookuser"]; $cookpass = $_COOKIE["cookpass"]; $adminpass = md5($adminpass); if($cookuser && $cookpass) { if(($cookuser == $adminuser) && ($cookpass == $adminpass)){ echo "<p class=\"editblog\">"; echo "<a class=\"editblog\" href=\"edit.php?type=0&piece={$row[id]}\">edit</a>"; echo "</p>"; } } echo "$entrieste"; } echo "</div>"; require("db/closedb.php"); echo "<span id=\"moreblogs\"><a href=\"blogs.php\">more entries</a></span>"; ?> </div> And then I end the div just before I close the database connection. When I do this, however, each object on the page gets skewed. Can this not be done, or why is it malfunctioning? What's strange is that my UMBRELLA div inside the WHILE loop works just fine. Thanks. Quote Link to comment Share on other sites More sharing options...
TheFilmGod Posted September 9, 2007 Share Posted September 9, 2007 You don't NEED to use the while() {} loop. Just do mysql_fetch_assoc three times. Each in different div tag. Quote Link to comment Share on other sites More sharing options...
FridayRain Posted September 9, 2007 Author Share Posted September 9, 2007 If I do that, how do I get the second two queries to return the second and third entries, respectively? So it's not possible in a WHILE loop? Quote Link to comment Share on other sites More sharing options...
FridayRain Posted September 9, 2007 Author Share Posted September 9, 2007 Any other ideas? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2007 Share Posted September 9, 2007 You don't NEED to use the while() {} loop. Just do mysql_fetch_assoc three times. Each in different div tag. Each mysql_fetch_assoc will get the next record. Quote Link to comment Share on other sites More sharing options...
FridayRain Posted September 9, 2007 Author Share Posted September 9, 2007 Feh. Stupid mistake. The div start tag needed to go above the first echo statement. A few lines down. This: while($row = mysql_fetch_array($result)) { $date = $row[date]; $entriesti = "<h2>$row[title]</h2>"; $entrieste = nl2br("<p>$row[text]</p><br /><br />"); echo "<div class=\"blogentry\">"; echo $entriesti; Instead of: while($row = mysql_fetch_array($result)) { $date = $row[date]; echo "<div class=\"blogentry\">"; $entriesti = "<h2>$row[title]</h2>"; $entrieste = nl2br("<p>$row[text]</p><br /><br />"); echo $entriesti; Quote Link to comment 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.