Results 1 to 9 of 9
-
May 1st, 2006, 12:47 PM #1
[php][mysql]Display Highest news id
I have a php/mysql news management system, and on my main page i want to display my latest news. Basically i need to include the page with the highest news id my pages are set like this:
"news.php?newsid=21"
Is there a way to do this?
-
May 1st, 2006, 12:50 PM #2
you need your query to be something like:
without knowing what your tables or variables are called, that's my best guess. basically you just need to ORDER BYCode:$result = mysql_query( "SELECT * FROM newstable LIMIT limitnum ORDER BY newsid ASC" )'
-
May 1st, 2006, 01:32 PM #3602Backend Specialist
postsif you want the highest id's first, you would use
(also the limit must come after order by)Code:SELECT * FROM newstable ORDER BY newsid DESC LIMIT limitnum
hthgo [here] if you need a host.
support my drinking problem
Im the guy wearing the obnoxiously large aviators
-
May 1st, 2006, 01:41 PM #4
I only want to show the highest news id, there will be links to the others...
-
May 1st, 2006, 02:26 PM #5
then LIMIT 1
@skoob: word. i couldn't remember the syntax off hand.
-
May 1st, 2006, 03:15 PM #6
Would it be ordered by DESC? To get the latest news?
Member #2 of the "I wont critique Timmytot's designs anymore" club.
-
May 1st, 2006, 03:30 PM #7602Backend Specialist
postsyou should really have a datetime field on the news entry. like "date_added" or something, and use that for ordering. using an auto_increment ID could work...but it won't work if for some reason you insert an ID manually to a lower available news ID.
@ sebs - Since the news ID will be 1 more than the previous news story, it will have a greater number, and you want to sort from highest to lowest to get the most recent news story added.go [here] if you need a host.
support my drinking problem
Im the guy wearing the obnoxiously large aviators
-
May 1st, 2006, 03:36 PM #8Yes skoob that would be DESC and type in number going doen
Originally Posted by skOOb
1
2
3
4
and sort by DESC 4 would be at the top, that woudl be the newest story.Member #2 of the "I wont critique Timmytot's designs anymore" club.
-
May 2nd, 2006, 08:05 AM #9
try this sql statement:
$result=mysql_query("select max(id) as maxID from tbltable");
$row=mysql_fetch_object($result);
echo $row->maxID;
this would output the maximum id number in the database
Similar Threads
-
Best way to make dynamic news section?
By prada in forum Flash IDEReplies: 0Last Post: April 19th, 2006, 10:40 AM -
news ticker: setInterval or is there a better way?
By sebstence in forum Flash IDEReplies: 1Last Post: February 22nd, 2006, 09:59 PM -
Displaying the news: PHP, Flash and MySQL
By mseerob in forum Flash IDEReplies: 0Last Post: February 2nd, 2006, 10:09 PM -
News ticker - unique identifier
By luxxx in forum ActionScript 2 (and Earlier)Replies: 0Last Post: January 30th, 2006, 09:12 PM -
Highlighting a text link with mouseover animation
By Nischint in forum Server-Side (PHP, SQL, ASP.NET, etc.)Replies: 11Last Post: September 8th, 2001, 02:54 PM

Reply With Quote


Bookmarks