I have a mysql database in which there is about hundreds of category for photo album. When i display the album using
"SELECT * FROM 'album' `status`='1' ORDER BY `cat_name` DESC LIMIT 10"
so it will display the last 10 categories but if i want to display only 15 categories in between from that hundreds of category what the query should be? i have try this.
"SELECT * FROM 'album' `status`='1' and `cat_id`='2' || `cat_id`='7' || `cat_id`='8' || `cat_id`='14' || `cat_id`='20' ORDER BY `cat_name` DESC LIMIT 10"
here its displaying that category which i want to display but it displaying that inactivate category also which i do not show here by using status
=’1′ (inactive status=0)
can any body help me with this
Advertisement
Answer
You have to put the WHERE
keyword before your conditions.
Also, instead of all of those OR
s or ||
s, use IN
.
SELECT * FROM album WHERE status = 1 AND cat_id IN (2,7,8,14,20) ORDER BY cat_name DESC LIMIT 10