Help - Search - Members - Calendar
Full Version: News Script Error.
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
iCemaT
I have been looking on a news script for long time, if someone have a nice newscript somewhere, please tell me.. wink.gif
This code is found in a tutorial, i didnt get it right blink.gif

Else i have error in this coding:
CODE
<?php
/* user config variables */
$max_items = 5; /* max number of news items to show */

function displayNews($all = 0) {
    /* bring in two variables
     * $db is our database connection
     * $max_items is the maximum number
     * of news items we want to display */
    global $db, $max_items;
    
    /* query for news items */
    if ($all == 0) {
        /* this query is for up to $max_items */
        $query = "SELECT id,title,newstext," .
                 "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
                 "FROM news ORDER BY postdate DESC LIMIT $max_items";
    } else {
        /* this query will get all news */
        $query = "SELECT id,title,newstext," .
                 "DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
                 "FROM news ORDER BY postdate DESC";
    }
    $result = mysql_query ($query);
    while ($row = mysql_fetch_assoc ($result)) {
        /* display news in a simple table */
        echo "<TABLE border=\"1\" width=\"300\">\n";

        /* place table row data in
         * easier to use variables.
         * Here we also make sure no
         * HTML tags, other than the
         * ones we want are displayed */
        $date = $row['date'];        
        $title = htmlentities ($row['title']);
        $news = nl2br (strip_tags ($row['newstext'], '<a><b><i><u>'));
        
        /* display the data */
        echo "<TR><TD><b>$title</b> posted on $date</TD></TR>\n";
        echo "<TR><TD>$news</TD></TR>\n";
        
        /* get number of comments */
        $comment_query = "SELECT count(*) FROM news_comments " .
                         "WHERE news_id={$row['id']}";
        $comment_result = mysql_query ($comment_query);
        $comment_row = mysql_fetch_row($comment_result);
        
        /* display number of comments with link */
        echo "<TR><TD><a href=\"{$_SERVER['PHP_SELF']}" .
             "?action=show&id={$row['id']}\">Comments</a>" .
             "($comment_row[0]}</TD></TR>\n";
        
        /* finish up table*/
        echo "</TABLE>\n";
        echo "<BR>\n";
    }
    
    /* if we aren't displaying all news,
     * then give a link to do so */
    if ($all == 0) {
        echo "<a href=\"{$_SERVER['PHP_SELF']}" .
             "?action=all\">View all news</a>\n";
    }
}
nitsuarox
I have one at http://ymcodes.zzl.org ( that page might not load first try just keep refreshing it until it does )
Adam
Just looking at that script I can see all it does it try to output a database, a news script is a tad more complicated.

You will want various items, a database to hold your news articles, a system to add / manage current new articles and a script to display all news articles on your website... so unless you have more code than the code above, it is totally useless unless you know how to code the rest of the sections you require.

A free news system I know of is http://cutephp.com/
Clew
there's a tutorial thingy HERE but i warn you, because of the safe mode, it doesn't work. if you get safemode removed it might.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.