Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Prev Cat / Next Cat / First / Last Cat

Quote Reply
Prev Cat / Next Cat / First / Last Cat
To fetch the prev cat i use in php

SELECT * FROM Category
WHERE Name < ( SELECT Name FROM Category WHERE CategoryID = $catid )
ORDER BY Name DESC limit 0,1

To fetch the next cat

SELECT * FROM Category
WHERE Name < ( SELECT Name FROM Category WHERE CategoryID = $catid )
ORDER BY Name ASC limit 0,1


Unfortunately i have no idea how to tell this to LSQL.


Then i have to check, if a cat is the last or the first one, because the prev to the first should be the last, the next to the last one should be the first one.

Is there any solution for this, please?


Hmmm, i just understand that i still have the name.

Then i should maybe ask:

SELECT * FROM Category
WHERE Name < $name
ORDER BY Name ASC limit 0,1

I will try it in a minute ...
Quote Reply
Re: [Robert] Prev Cat / Next Cat / First / Last Cat In reply to
Hi,

You can't do WHERE Name < $name , as thats asking for an int check, not string :)

Quote:
SELECT * FROM Category
WHERE Name < ( SELECT Name FROM Category WHERE CategoryID = $catid )
ORDER BY Name DESC limit 0,1

You sure? That doesn't look right to me.

Anyway, if you really want to do it like that - you can use the do_query() function:

Code:
my $value = $DB->table("Category")->do_query(qq|SELECT * FROM Category
WHERE Name < ( SELECT Name FROM Category WHERE CategoryID = $catid )
ORDER BY Name DESC limit 0,1|)->fetchrow_hashref || {}

Still not sure what your Name < x is supposed to be doing?

http://dev.mysql.com/...l#operator_less-than

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Prev Cat / Next Cat / First / Last Cat In reply to
Thnk you, Andy.
I have done it with the normal way, because a second query was not necessary.
Now i have a carousel like:

Last Cat|First Cat|Second Cat

n-1 cat|n cat|n+1 cat

last-1 cat|last cat|first cat

or

First|Second|Third

n-1 cat|n cat|n+1 cat

Last-2|Last-1|Last

as a small pagination under every category page. :)

Last edited by:

Robert: May 26, 2016, 7:33 AM