Jump to content


News Script (PHP/MySQL) (a little help!)


2 replies to this topic

#1 kyleblackman

    Young Padawan

  • Members
  • Pip
  • 25 posts

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?

Edited by kyleblackman, 25 January 2007 - 03:55 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 25 January 2007 - 04:38 PM

Well, it would be simple like this.
$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. :D


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 kyleblackman

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 26 January 2007 - 12:15 PM

View PostDemonslay, on Jan 25 2007, 05:38 PM, said:

Well, it would be simple like this.
$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