Edited by kyleblackman, 25 January 2007 - 03:55 PM.
News Script (PHP/MySQL) (a little help!)
Started by kyleblackman, Jan 25 2007 01:32 PM
2 replies to this topic
#1
Posted 25 January 2007 - 01:32 PM
Ive got a little news script on my site and im limiting it to only the 4 most recent entries. However to save space, i want my query to display the date, title, and message of the MOST recent news post, and then just the date and title of the rest of my more recent news stories. whats the best way to achieve this?
#2
Posted 25 January 2007 - 04:38 PM
Well, it would be simple like this.
Of course you can change your formatting and such.
Interesting, I just found out that IPB automatically converts line breaks from '\n' in the code block BBCode lol.
$query = mysql_query("SELECT `date`, `title`, `message` FROM `news` LIMIT 1") or die(mysql_error());
$most_recent = mysql_fetch_array($query);
echo "<div class=\"title\">{$most_recent['title']} (<em>{$most_recent['date']}</em>)</div><div class=\"message\">{$most_recent['message']}</div>";
$query = mysql_query("SELECT `date`, `title` FROM `news` LIMIT 1, 3") or die(mysql_error()); // You may have to edit this LIMIT clause, I'm not good at them lol
while($news = mysql_fetch_array($query)) echo "<div class\"title\">{$news['title']} (<em>{$news['date']}</em>)</div>";
Of course you can change your formatting and such.
Interesting, I just found out that IPB automatically converts line breaks from '\n' in the code block BBCode lol.
Edited by Demonslay, 25 January 2007 - 04:40 PM.
#3
Posted 26 January 2007 - 12:15 PM
Demonslay, on Jan 25 2007, 05:38 PM, said:
Well, it would be simple like this.
Of course you can change your formatting and such.
Interesting, I just found out that IPB automatically converts line breaks from '\n' in the code block BBCode lol.
$query = mysql_query("SELECT `date`, `title`, `message` FROM `news` LIMIT 1") or die(mysql_error());
$most_recent = mysql_fetch_array($query);
echo "<div class=\"title\">{$most_recent['title']} (<em>{$most_recent['date']}</em>)</div><div class=\"message\">{$most_recent['message']}</div>";
$query = mysql_query("SELECT `date`, `title` FROM `news` LIMIT 1, 3") or die(mysql_error()); // You may have to edit this LIMIT clause, I'm not good at them lol
while($news = mysql_fetch_array($query)) echo "<div class\"title\">{$news['title']} (<em>{$news['date']}</em>)</div>";
Of course you can change your formatting and such.
Interesting, I just found out that IPB automatically converts line breaks from '\n' in the code block BBCode lol.
awesome demonslay! thanks! whats ironic is that i JUST figured this method out on my own right before i read this. well it was an idea i had, i wasnt sure if it would work but thanks!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
