Click here to Skip to main content
15,888,610 members
Home / Discussions / Database
   

Database

 
AnswerRe: IF Else Statement in SQL Statment Pin
nelsonpaixao6-Oct-08 14:50
nelsonpaixao6-Oct-08 14:50 
AnswerRe: IF Else Statement in SQL Statment Pin
mstfnoor7-Oct-08 22:54
mstfnoor7-Oct-08 22:54 
AnswerRe: IF Else Statement in SQL Statment Pin
Kevin Horgan23-Oct-08 2:19
Kevin Horgan23-Oct-08 2:19 
Questiongenerate database to word from sql 2005 Pin
irvinia5-Oct-08 19:12
irvinia5-Oct-08 19:12 
AnswerRe: generate database to word from sql 2005 Pin
Wendelius6-Oct-08 7:05
mentorWendelius6-Oct-08 7:05 
AnswerRe: generate database to word from sql 2005 Pin
nelsonpaixao6-Oct-08 14:56
nelsonpaixao6-Oct-08 14:56 
GeneralRe: generate database to word from sql 2005 Pin
irvinia6-Oct-08 16:38
irvinia6-Oct-08 16:38 
QuestionFilters Pin
GxSau5-Oct-08 8:50
GxSau5-Oct-08 8:50 
Hi, I'm working on a site similar to newegg.com and I'm kinda stuck on the filters.

I know the best way would be javascript, however i don't know any library that can accomplish filters like those. So i was doing it in the old way (php > mysql query)

The problem is the optimization, i can't find a good method to do this. i designed the tables this way..

table item {item_id,category_id}
1,1
2,1
3,2
4,1

table filter {item_id,filter_id}
1,100
1,101
1,102
2,99
2,100
3,0
4,5
4,102

Let's say i want to show all items from cateogry 1, so i need to create the filters to be shown. the filters should be something like this

Filter | quantity of items
100 (2)
101 (1)
102 (2)
99 (1)
5 (1)

this is my query

select count(filter_id), filter_id
from filter
where item_id in (select item_id from item where category_id = 1)
and filter_id not in () -- this isn't used in first instance, only when an user click on a filter.
group by filter_id

That's the easy part, now if an user select a filter i need to show the items filtered. This is what i use.

select *
from item
where item_id in (
-- this is only for removing the null results
select item_id
from (
select
-- this shows only those items that have all the filter_id selected by the user
case when count(*) = ".count(explode(',',validateFilters($_GET['filters'])))." then item_id end
from filter
where filter_id in ( ".validateFilters($_GET['filters'])." )
group by item_id
) as p
where item_id is not null
)
and category = 1

and then i have to use that query inside the filter query to get the new filters

select count(filter_id), filter_id
from filter
where item_id in ( all the query above)
and filter_id not in ( ".validateFilters($_GET['filters'])." )
group by filter_id

is there an easier way?

Thank You.

modified on Sunday, October 5, 2008 2:57 PM

QuestionIndex on a foreign key Pin
Brendan Vogt5-Oct-08 5:58
Brendan Vogt5-Oct-08 5:58 
AnswerRe: Index on a foreign key Pin
Wendelius5-Oct-08 6:08
mentorWendelius5-Oct-08 6:08 
GeneralRe: Index on a foreign key Pin
Brendan Vogt5-Oct-08 6:51
Brendan Vogt5-Oct-08 6:51 
Questionbool matrix Pin
Robert19745-Oct-08 0:59
Robert19745-Oct-08 0:59 
AnswerRe: bool matrix Pin
Blue_Boy5-Oct-08 2:14
Blue_Boy5-Oct-08 2:14 
AnswerRe: bool matrix Pin
Wendelius5-Oct-08 5:02
mentorWendelius5-Oct-08 5:02 
QuestionSQL quote problem Pin
Yulianto.4-Oct-08 22:22
Yulianto.4-Oct-08 22:22 
AnswerRe: SQL quote problem Pin
Meysam Mahfouzi4-Oct-08 22:37
Meysam Mahfouzi4-Oct-08 22:37 
AnswerRe: SQL quote problem Pin
Vimalsoft(Pty) Ltd5-Oct-08 0:08
professionalVimalsoft(Pty) Ltd5-Oct-08 0:08 
AnswerRe: SQL quote problem Pin
Mark Churchill5-Oct-08 4:23
Mark Churchill5-Oct-08 4:23 
QuestionFull-text search 900 bytes limitation Pin
Meysam Mahfouzi4-Oct-08 21:08
Meysam Mahfouzi4-Oct-08 21:08 
AnswerRe: Full-text search 900 bytes limitation Pin
Wendelius5-Oct-08 4:56
mentorWendelius5-Oct-08 4:56 
GeneralRe: Full-text search 900 bytes limitation Pin
Meysam Mahfouzi5-Oct-08 8:52
Meysam Mahfouzi5-Oct-08 8:52 
GeneralRe: Full-text search 900 bytes limitation Pin
Wendelius5-Oct-08 9:01
mentorWendelius5-Oct-08 9:01 
GeneralRe: Full-text search 900 bytes limitation [modified] Pin
Meysam Mahfouzi5-Oct-08 9:55
Meysam Mahfouzi5-Oct-08 9:55 
Questionwho is better Pin
abiniyam3-Oct-08 22:11
abiniyam3-Oct-08 22:11 
AnswerRe: who is better Pin
Jaime Olivares4-Oct-08 2:09
Jaime Olivares4-Oct-08 2:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.