I need some advice here.
I just made a news script that allows one to post news articles, edit and delete them, and a page that displays them. All works great.
Now, I want to have it so the user can input a number, say 10, and after 10 news stories, the script stops displaying news stories, there is a link to an archive page, and then the arhcive page displays all the news after the 10 already displayed on the main page.
So basically, the 10 newest news stories on the main page, then the rest show on an archive page. What is the best way to do this?
my DB has a news table tat i'm working off of with this structure:
they are all not null, and the userid has a default value of 0 and date field has the default value lsited.
my current code to display all news articles:
Anyone have any ideas?
I just made a news script that allows one to post news articles, edit and delete them, and a page that displays them. All works great.
Now, I want to have it so the user can input a number, say 10, and after 10 news stories, the script stops displaying news stories, there is a link to an archive page, and then the arhcive page displays all the news after the 10 already displayed on the main page.
So basically, the 10 newest news stories on the main page, then the rest show on an archive page. What is the best way to do this?
my DB has a news table tat i'm working off of with this structure:
newsid int(11) No auto_increment primary
subject text No
body longtext No
username text No
userid int(11) No 0
date datetime No 0000-00-00 00:00:00
email text No
subject text No
body longtext No
username text No
userid int(11) No 0
date datetime No 0000-00-00 00:00:00
email text No
my current code to display all news articles:
PHP Code:
$query1= "Select newsid from news";
$result1= mysql_query($query1)
or die("couldn't execute query");
$num1= mysql_num_rows($result1);
if ($num1==0)
{
echo "There are currently no news articles to display. Please check back later!";
}
for ($i=1; $i<=$num1; $i++)
{
$query2= "select * from news where newsid= '$i'";
$result2= mysql_query($query2)
or die("couldn't execute query");
while ($r= mysql_fetch_array($result2))
{
$subject= $r["subject"];
$post= $r["body"];
$name= $r["username"];
$date= $r["date"];
$email=$r["email"];
$date= date("F jS, Y, G:i a", strtotime($date));
echo "<font size='+1'><b>$subject </b></font><br><br>";
echo "$post <br><br>";
echo "<font size='-1'><i>posted by <a href='mailto:$email'>$name</a> on $date</i></font><br><br><br>";
}
}
Comment