ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using SQL to create a Previous and Next link

January 14, 2010 1:30pm

Subscribe [1]
  • #1 / Jan 14, 2010 1:30pm

    onepanman

    44 posts

    I am currently using a SQL query to create a previous and next link on a product page. The follow query is what I currently have working:

    {exp:query sql="SELECT exp_category_posts.cat_id,exp_category_posts.entry_id, exp_weblog_titles.entry_id, exp_weblog_titles.url_title AS ut FROM exp_weblog_titles, exp_category_posts WHERE title < '{title}' AND weblog_id = {weblog_id} AND status = 'open' AND cat_id = '36' AND exp_category_posts.entry_id = exp_weblog_titles.entry_id ORDER BY title DESC LIMIT 1"}
    
    <a href="http://{path="><<< PREVIOUS</a> {/exp:query}
    {exp:query sql="SELECT exp_category_posts.cat_id,exp_category_posts.entry_id, exp_weblog_titles.entry_id, exp_weblog_titles.url_title AS ut FROM exp_weblog_titles, exp_category_posts WHERE title > '{title}' AND weblog_id = {weblog_id} AND status = 'open' AND cat_id = '36' AND exp_category_posts.entry_id = exp_weblog_titles.entry_id ORDER BY title DESC LIMIT 1"}
    
    <a href="http://{path="><<< NEXT</a> {/exp:query}

    This is basically grabbing the title and category fields and if the category equals 36 (a particular product line), it will create the links for previous and next. I would post this under the original post that I found it in, but it has been a long while and could not find it.

    Anyways, the only problem I have with this code, is that after it reaches the last product the next does not show up (as expected). I would prefer it to still show next but just loop to back to the beginning. Is this possible? Same for the previous.

    Thanks,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases