简体   繁体   中英

Admin Panel: enter text, post to database, blog style

I'm trying to re-create my fire department's website, as it's strictly a HTML website, and far from professional. Everything is going excellently, including the log in system and pave navigation. However, I've run into a slight bump in the road that might be beyond my current skill level:

How do I have the person who's logged into the admin panel, enter information in a blog-like style, to post it to the front page (such as a news post / website announcement)?

It's actually a lot like this post here - Editor tools at the top, and when it posts, it has the formatting and breaklines. When I put it in my database, it shows up as one clump wall of text, with no formatting.

INDEX.PHP

<?
            $qnews = mysqli_query($link, "SELECT * FROM news WHERE archive = 0 ORDER BY time DESC");
            while($rownews = mysqli_fetch_array($qnews))
            {
                if(empty($rownews))
                {
                    echo "<div class=\"news\"><h2>There are no announcements posted.</h2></div>";
                }
                else
                {
                echo "<div class=\"news\">";
                echo "<h2>";
                echo $rownews['title'];
                echo "</h2><p>";
                echo $rownews['body'];
                echo "</p><br />";
                echo "<span class=\"newsfooter\">Posted on <font color=\"#FA0000\">";
                echo date("F d Y @ H:i", strtotime($rownews['time']));
                echo "</font> by <font color=\"#0000FA\">";
                echo $rownews['creator'];
                echo "</font></span></div>";
                }
            }?>

MySQL Table

news
-- id (A_I) (UNIQUE)
-- title VARCHAR(50)
-- body VARCHAR(5000)
-- created DATETIME(25) Default:CURRENT_TIMESTAMP
-- edited DATETIME(25)
-- archived INT(1) Default:0

Am I way out of my league, or can someone point me in the right direction?

I think changing

echo $rownews['body'];

to

echo nl2br($rownews['body']);

can give you at least the linebreaks, if they are present in the text stored in the database. Concerning additional formatting, it would be interesting to see how is a single entry represented in the database (or in the HTML output), could you add that to your question?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM