Jump to content


Help with MySQL/PHP

  • Please log in to reply
2 replies to this topic

#1 blurd

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 15 August 2006 - 03:28 AM

I'm making a news script for my site and everything works, like i have the script reading the data from the database and everything.  BUT, every time i add new news, it gets put under the old ones and i want it on top.  Here is my script and thanks to anyone who helps.

include 'config.php';
include 'opendb.php';

$query  = "SELECT Username,Date,Time,Title,Content FROM news";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
echo "<TABLE WIDTH='100%' BORDER=0 CELLPADDING=2 CELLSPACING=0><TR style='text-align:center;vertical-align:middle;font-size:12pt;font-weight:bold;'><TD width='15%' style='font-size:10pt;border-left:1px solid black;border-bottom:1px solid black;border-top:1px solid black;'>$row[Date] At $row[Time] </TD><TD width='70%' style='border-top:1px solid black;border-bottom:1px solid black;'> $row[Title] </TD><TD width='15%' style='font-size:10pt;border-right:1px solid black;border-bottom:1px solid black;border-top:1px solid black;'> By: $row[Username]</TD></TR><TR style='text-align:center;vertical-align:middle;font-size:10pt;'><TD width='15%' style='border-left:1px solid black;border-bottom:1px solid black;'>&nbsp</TD><TD width='70%' style='border-bottom:1px solid black;'> $row[Content] </TD><TD width='15%' style='border-right:1px solid black;border-bottom:1px solid black;'>&nbsp</TD></TR></TABLE><BR>";

include 'closedb.php';

#2 yarub

  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts
  • LocationSioux City, IA

Posted 15 August 2006 - 04:05 AM

$query  = "SELECT Username,Date,Time,Title,Content FROM news ORDER BY Time DESC";

Replace Time with whatever field you want to order it by. Descending will make it so the newer posts will show first.

#3 blurd

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 15 August 2006 - 06:51 AM

Thanks Man, Exactly what i needed :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users