Limiting MySQL output

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Limiting MySQL output

Post by f1nutter »

Hi all!,

I am trying to set-up a news page on my site which
a) only lists the 10 most recent entries
b) writes the first sentance/100 characters of each story with a "more" button to expand the story.

I have the news articles in a db with auto_increment id numbers, which is then sorted in descending order to give the most recent story first. However,

Code: Select all

SELECT TOP 10 story FROM news
does not work (it does in Access, so the syntax seems correct!) I am using MySQL 3.23.49, hosted be a company, so no upgrade suggestions!.

I wanted MySQL to limit the size of the story, because if a user then reads the article, the whole lot would need to be parsed twice and I guess in PHP this is not efficient.

If any one can help with either of these problems I would be greatful.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

SELECT story FROM news ORDER BY <id> DESC LIMIT 10

then cut the string with php
Post Reply