Results 1 to 5 of 5

Thread: Simple Blog

  1. #1
    Member silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    189

    Question Simple Blog 27 May 2011 @ 11.02

    Hey guys,

    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.

    Thanks

    Silversurfer
      Reply With Quote

  2. #2
    Senior Member Jason's Avatar
    Join Date
    Dec 2008
    Posts
    911

    Default 27 May 2011 @ 11.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.

    Code:
    SELECT * FROM posts ORDER BY id DESC
    - or -

    Code:
    SELECT * FROM posts ORDER BY created DESC
    -or -

    Code:
    SELECT * FROM posts ORDER BY date_published DESC
      Reply With Quote

  3. #3
    Member silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    189

    Question 27 May 2011 @ 11.28

    Thanks very much Jason,

    Works great
      Reply With Quote

  4. #4
    Senior Member Jason's Avatar
    Join Date
    Dec 2008
    Posts
    911

    Default 27 May 2011 @ 11.36

    You may want to limit your results. You can do that by appending 'LIMIT <start> <number>'..

    Code:
    LIMIT 0, 5
    Code above gets the first 5 posts.

    Code:
    LIMIT 5, 5
    Code above gets posts 6-10
      Reply With Quote

  5. #5
    Member silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    189

    Question 27 May 2011 @ 12.07

    Thats great thanks Jason,

    I know it was a bit of a dum dum question thanks anyway
      Reply With Quote

Similar Threads

  1. simple jquery sliding div - how?
    By trixiemay in forum Javascript Libraries
    Replies: 0
    Last Post: 30 Sep 2010, @ 00.08
  2. Simple PHP Framework Questions
    By webroasters in forum PHP, ASP & Java
    Replies: 6
    Last Post: 9 Jul 2010, @ 09.34
  3. Simple CMS
    By Michael in forum Content Management Systems, Blogs & Forums
    Replies: 5
    Last Post: 18 Dec 2009, @ 20.58
  4. Really simple illustrator question
    By CloudedVision in forum Imagery, Graphics & Typography
    Replies: 2
    Last Post: 15 Feb 2009, @ 10.19

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •