dddragon2 Posted July 14, 2008 Share Posted July 14, 2008 I am currently creating a script that read a table of articles that I have in a MySql table. So For example, I have in the table: Id,name,date 1,article1,7/1/08 2,article2,7/2/08 5,myarticle,7/3/08 6,article3,7/6/08 ..... So I have a reader page that will pull ID 5, myarticle for example and display the article on the screen. I want to be able to add a Previous link that points to article2 and a Next link that article3. The previous and next links are sorted by date. So if i added another article dated 7/4 the next would point to that article instead. A good example of this would be when you open and email up at gmail or hotmail. I can't think of an efficient way to do this. The only solution that I can think of is pulling the whole table of data and traversing the list to find the article before and after the article I am looking for. Is there a way to make a MySql query that will pull the entry after myarticle and pull the entry before myarticle? Or is there another more efficient way to do this? Link to comment https://forums.phpfreaks.com/topic/114738-php-article-reader-help/ Share on other sites More sharing options...
stuart.cole Posted July 15, 2008 Share Posted July 15, 2008 Is there a way to make a MySql query that will pull the entry after myarticle I think what you are asking for is related to limiting the number of results you receive, for example if you have select * from Articles WHERE date >=7/3/08 LIMIT 0,1 - I've not called using this date format previously but I believe it should work. you would get a reply from the database with the results showing articles 5 and 6, the >= means it will show results where the date is equal to or greater than '7/3/08', and the LIMIT starts at result 0 (the first result) and carries on for 1 more. and pull the entry before myarticle? If you use the above method but call <=5 you will get items for Id 5 and below, and as long as you 'ORDER by date DESC' the query it should work for the items below. Link to comment https://forums.phpfreaks.com/topic/114738-php-article-reader-help/#findComment-590043 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.