View Full Version : PHP + MySQL News System
k@mi
Sat 18th Aug '01, 7:20pm
I've written most of the code to the thing, but the part i'm faltering on is how to get the news posts with the same date to appear under the same date header
Site: http://www.kidzonfire.org/new/
i'm playing around with stuff, but i'm stumped on how to do that
-----------
Date
-----------
*Subject
Message
*Subject
Message
-----------
Date
-----------
etc.........
k@mi
Sat 18th Aug '01, 7:38pm
here's the code i'm using now
//selecting the 'kidzonfire' database to use
mysql_select_db("kidzonfire");
//Hey Look, it's todays damn date...
$today = date("l F dS Y");
//Setting the default mode for the news script
if(!isset($mode))
{
$mode = "news";
}
if ($mode == "news")
{
//This is the printnews part of the code, prints a specified number of news posts in the format specified here
//MySQL Query Stuff here
$query = "SELECT * FROM news ORDER BY newsid DESC LIMIT 0,30";
$result = mysql_query($query);
//Defining the data retrieval loop
while($query_data = mysql_fetch_object($result))
{
echo "<hr noshade>";
echo "<span class='date'>";
echo "<img src='styles/$style_name/bullet.gif' class='bullet'>".stripslashes($query_data->date)."</span>";
echo "<hr class='bottom' noshade>";
echo "<span class='p'><img src='styles/$style_name/bullet.gif' class='bullet'><span class='newstitle'>". stripslashes($query_data->subject) ."</span><img src='styles/$style_name/bullet.gif' class='bullet'>";
echo "<a href='$PHP_SELF?page=$page&mode=filter&div=".stripslashes($query_data->category)."'>".stripslashes($query_data->category)."</a> - ";
echo stripslashes($query_data->user) ."</span>";
echo "<span class='p2'>". stripslashes($query_data->message) ."</span>";
}
//Closing the mysql connection
mysql_close($db);
}
if ($mode == "filter")
{
//This is the printnews part of the code, prints a specified number of news posts in the format specified here
//MySQL Query Stuff here
$query = "SELECT * FROM news WHERE category='$div' ORDER BY newsid DESC LIMIT 0,30";
$result = mysql_query($query);
//Defining the data retrieval loop
while($query_data = mysql_fetch_object($result))
{
echo "<hr noshade>";
echo "<span class='date'>";
echo "<img src='styles/$style_name/bullet.gif' class='bullet'>".stripslashes($query_data->date)."</span>";
echo "<hr class='bottom' noshade>";
echo "<span class='p'><img src='styles/$style_name/bullet.gif' class='bullet'><span class='newstitle'>". stripslashes($query_data->subject) ."</span><img src='styles/$style_name/bullet.gif' class='bullet'>";
echo "<a href='$PHP_SELF?page=$page&mode=filter&div=".stripslashes($query_data->category)."'>".stripslashes($query_data->category)."</a> - ";
echo stripslashes($query_data->user) ."</span>";
echo "<span class='p2'>". stripslashes($query_data->message) ."</span>";
}
//Closing the mysql connection
mysql_close($db);
}
I use the date thing to get the calendar date of the time a news post was posted, and i want it to check if the two dates are the same, and if they are, the most recent post will be towards the top.
Mark Hensler
Sun 19th Aug '01, 1:35am
Just throw an IF statement in there.
//Defining the data retrieval loop
$tmp_date = "";
while($query_data = mysql_fetch_object($result)) {
if ($tmp_date != stripslashes($query_data->date)) {
// It's a new day, print the date
$tmp_date = stripslashes($query_data->date);
echo "<hr noshade>";
echo "<span class='date'>";
echo "<img src='styles/$style_name/bullet.gif' class='bullet'>".stripslashes($query_data->date)."</span>";
echo "<hr class='bottom' noshade>";
}
echo "<span class='p'><img src='styles/$style_name/bullet.gif' class='bullet'><span class='newstitle'>". stripslashes($query_data->subject) ."</span><img src='styles/$style_name/bullet.gif' class='bullet'>";
echo "<a href='$PHP_SELF?page=$page&mode=filter&div=".stripslashes($query_data->category)."'>".stripslashes($query_data->category)."</a> - ";
echo stripslashes($query_data->user) ."</span>";
echo "<span class='p2'>". stripslashes($query_data->message) ."</span>";
}
k@mi
Sun 19th Aug '01, 3:41am
thanks!
Chexbox
Sun 26th Aug '01, 5:56pm
How did you get started writing this News System?
vBulletin® v3.8.0 Beta 4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.