Jump to content

[SOLVED] Place each query result in a div?


FridayRain

Recommended Posts

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.