Thread: Simple Blog
Simple Blog 27 May 2011 @ 10.02
I am currently creating a simple PHP, MYSQL based blog so that I can supply my clients with a back-end news update page. I am aware of Blogger and other such services and it is because I am fed up of customising stylesheets on them that I am doing my own.
Anyway all working great, can add, delete and edit existing posts but I also want to list the posts on the page in the correct order by date. How is this typically done?
Is there a way of doing it with MYSQL or is it done with PHP ?
I am one of these lazy developers who tends to just use SELECT, INSERT INTO and DELETE with not much else I am afraid.
Guess it's because as I have never had the need to make sophisticated SQL commands.
Anyway your advice would be much appreciated.
27 May 2011 @ 10.25
Sophisticated? I think not!
Ideally your posts table will have one of - but preferably both of - the following columns.
id - (this would be int, would have the primary key and be set as auto_increment)
created - (this would be datetime)
Even better you would have a date_published field.
Assuming you have one of these you would do the following.
SELECT * FROM posts ORDER BY id DESC
SELECT * FROM posts ORDER BY created DESC
SELECT * FROM posts ORDER BY date_published DESC
27 May 2011 @ 10.36
You may want to limit your results. You can do that by appending 'LIMIT <start> <number>'..
LIMIT 0, 5
LIMIT 5, 5
27 May 2011 @ 11.07
Thats great thanks Jason,
I know it was a bit of a dum dum question thanks anyway
- By webroasters in forum PHP, ASP & JavaReplies: 6Last Post: 9 Jul 2010, @ 08.34
- By Michael in forum Content Management Systems, Blogs & ForumsReplies: 5Last Post: 18 Dec 2009, @ 19.58
- By CloudedVision in forum Imagery, Graphics & TypographyReplies: 2Last Post: 15 Feb 2009, @ 09.19