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
https://forums.phpfreaks.com/topic/68549-solved-place-each-query-result-in-a-div/
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;

Archived

This topic is now archived and is closed to further replies.

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