Blog system: show neighboring entries Jun05 '05

Feedback

# (1 of 1): Theoden

2 years, 10 months after the fact. (Wed 23 Apr 2008, 1:34 AM CST)

I have a couple of suggestions that can improve this. First, if your going to loop though all of the entries then you might as well also grab a unique id from the table, so that you can get the information directly. This eliminates the need for an array. Second, you can use two queries to get the same information with little php work. SELECT datetime FORM entries WHERE datetime < 'datetime current' ORDER BY datetime DESC LIMIT 1; SELECT * FROM entries WHERE datetime >= 'datetime previous' ORDER BY datetime ASC LIMIT 3; The second query uses the datetime returned by the first and returns 3 full entries of previous, current, and next in that order. Databases are much more efficient at sorting and finding than php.

RSS feed for comments on this post

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Return to entry.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

An approach to gathering "neighboring entries," for a typical blog system.

You are at the feedback permalink page for: Blog system: show neighboring entries

Read more...