473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

selecting only a certain number of bits of data

I have just started learning php and mysql. I am trying to make a news page
for a site where you can enter news in a form and it appears on the news
page. That is done, fairly simple. I've also ordered them with the latest
first. I would now like to only show a certain number of the news articles.
Say the latest five. Each article is numbered so I guess I would use that
but i'm not really sure how to do it. Any ideas?

Apr 16 '07 #1
3 1244
roondog wrote:
I have just started learning php and mysql. I am trying to make a news page
for a site where you can enter news in a form and it appears on the news
page. That is done, fairly simple. I've also ordered them with the latest
first. I would now like to only show a certain number of the news articles.
Say the latest five. Each article is numbered so I guess I would use that
but i'm not really sure how to do it. Any ideas?
If you have a date field you can order by date descending, but ID is
fine if you happy with that... so...

SELECT * FROM news ORDER BY news_id DESC LIMIT 5
Apr 16 '07 #2
roondog wrote:
I would now like to only show a certain number of the news articles.
Say the latest five.
Certain databases allow you to use a "LIMIT" clause to limit the number of
results returned by a SELECT query. Because this is not part of the
official SQL standard, the exact syntax varies between databases. Here are
some examples:

MySQL:
SELECT * FROM articles ORDER BY created_date DESC LIMIT 5;

PostgreSQL:
SELECT * FROM articles ORDER BY created_date DESC LIMIT 5;

Microsoft SQL Server:
SELECT TOP 5 * FROM articles ORDER BY created_date DESC;

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Apr 16 '07 #3

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:i7************@ophelia.g5n.co.uk...
roondog wrote:
I would now like to only show a certain number of the news articles.
Say the latest five.

Certain databases allow you to use a "LIMIT" clause to limit the number of
results returned by a SELECT query. Because this is not part of the
official SQL standard, the exact syntax varies between databases. Here are
some examples:

MySQL:
SELECT * FROM articles ORDER BY created_date DESC LIMIT 5;

PostgreSQL:
SELECT * FROM articles ORDER BY created_date DESC LIMIT 5;

Microsoft SQL Server:
SELECT TOP 5 * FROM articles ORDER BY created_date DESC;
Thanks for that I knew there was something simple I was missing.
Apr 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon G Best | last post by:
Hello! The C++ standard library provides facilities for finding out the sizes (and other such stuff) of numeric types (::std::numeric_limits<>, for example). What I would like to do is to...
5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
5
by: uthuras | last post by:
Machine : AIX 5.2 Product : UDB DB2 Release 8.1 FP4a I have problem loading data into destination table. The data file is huge with more than 6 Million records. This what i have done 1....
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting -1 value, eventhough 1000 of records are selected....
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
2
by: Ron | last post by:
How can I select a certain number of characters from a string, without selecting the whole string? For example, I want the first 50 characters of a 500 character string in my database. What...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
13
by: lane straatman | last post by:
I'm trying to figure out what data type is appropriate to represent a card in a game. The idea that I thought was going to work was a struct, foo, with two integer fields and two fields of char...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.