Click here to Skip to main content
15,902,112 members
Home / Discussions / Database
   

Database

 
GeneralRe: Denormalisation Quandary Pin
Mark Churchill6-Oct-08 5:32
Mark Churchill6-Oct-08 5:32 
QuestionExecute macro word from sql 2005 Pin
irvinia6-Oct-08 1:24
irvinia6-Oct-08 1:24 
AnswerRe: Execute macro word from sql 2005 Pin
ChandraRam6-Oct-08 2:12
ChandraRam6-Oct-08 2:12 
GeneralRe: Execute macro word from sql 2005 Pin
irvinia6-Oct-08 16:46
irvinia6-Oct-08 16:46 
AnswerRe: Execute macro word from sql 2005 Pin
Wendelius6-Oct-08 7:08
mentorWendelius6-Oct-08 7:08 
GeneralRe: Execute macro word from sql 2005 Pin
irvinia6-Oct-08 16:46
irvinia6-Oct-08 16:46 
QuestionBackup Database is terminating abnormally Pin
Rupesh Kumar Swami5-Oct-08 23:01
Rupesh Kumar Swami5-Oct-08 23:01 
AnswerRe: Backup Database is terminating abnormally Pin
HemJoshi6-Oct-08 1:37
HemJoshi6-Oct-08 1:37 
QuestionSql Query Pin
Ha_805-Oct-08 22:59
Ha_805-Oct-08 22:59 
AnswerRe: Sql Query Pin
Rupesh Kumar Swami5-Oct-08 23:05
Rupesh Kumar Swami5-Oct-08 23:05 
AnswerRe: Sql Query Pin
nelsonpaixao6-Oct-08 14:17
nelsonpaixao6-Oct-08 14:17 
QuestionIF Else Statement in SQL Statment Pin
HatakeKaKaShi5-Oct-08 20:45
HatakeKaKaShi5-Oct-08 20:45 
AnswerRe: IF Else Statement in SQL Statment Pin
Ashfield5-Oct-08 21:03
Ashfield5-Oct-08 21:03 
GeneralRe: IF Else Statement in SQL Statment Pin
Paul Conrad6-Oct-08 18:40
professionalPaul Conrad6-Oct-08 18:40 
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 

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.