You are here:

PHP6/Am I on right track?

Advertisement


Question
QUESTION: Hi..
I'm currently learning PHP and is planning to make my own website.
The thing I want to happen is somewhat complicated so my database structure is somewhat different

i have items on my record and each item have n number of detail for example length size madein
not all items have same number of detail so i made a mapping table
of tItems and tDetail which i named tItems_tDetails_Mapping

now i want to filter my record
do i already do that on when i select the record or should i get all my records and filter them afterward?

also im planning to filter my record using a loop to construct my sql query which will return something like this

select tItems.ID, tItems.Description from tItems where tItems.ID IN
(
   select tItems_tDetails_Mapping.ItemID from tItems_tDetails_Mapping where
      tItems_tDetails_Mapping.DetailID="3" and tItems_tDetails_Mapping.Detail="Italy"    
)

AND  tItems.ID IN
(
   select tItems_tDetails_Mapping.ItemID from tItems_tDetails_Mapping where
      tItems_tDetails_Mapping.DetailID="2" and tItems_tDetails_Mapping.Detail="70cm"
)

a whole sub query is added for each detail the user want to filter
for example user only want to see all made in Italy then there is only one subquery
if the user want to filter all made in italy and have detail of 70cm then i will have 2 sub query
the first one finding all that is 70cm and then find all that is italy and only those that is found by BOTH query will be returned

Q: Am I on the right track?

Many thanks in advance

ANSWER: Hey Jeric

The SQL code looks fine to me. Can you export the SQL schema for the respective table and upload it on dropbox or anywhere and send me the link? Thats how I can confirm if its a good way to do it.



---------- FOLLOW-UP ----------

DatabaseDesign
DatabaseDesign  
QUESTION: The code does work
What I was trying to ask is am I doing it the right way?
Is my database designed right? How would an experienced developer design it to achieve what I want which is to
-have an item that have N number of detail like madein, length, weight, color,etc
-Be able to search items
-Be able to filter the items searched with N number of filters
lets say i only want to filter all length = 70cm
then i want to filter length = 70cm and madein = USA

I do know the design would do the thing I need
but what would be best approach to do this?

Answer
Yeah

I meant the same thing, thats why I asked for the mySQL schema, to have a look at it and suggest things if any. Multiple SQL queries are not a good idea btw. You should always do it via joins and sub queries.

So instead of asking his follow up question and understanding my answer, this guy Jeric the Jerk gives me

Knowledgeability - 2
Clarity of response - 2
Politeness - 5
Nomination - No
Prestige Point - 0
Comment - NONE

So thats why we sped time to help people on the internet? Seriously?

PHP6

All Answers


Answers by Expert:


Ask Experts

Volunteer


Fahd Murtaza

Expertise

I can answer everything PHP.

Experience

10 years of web development with over 5 years with PHP.

Organizations
R&D Muscat Oman. Reality CG Oman www.realitycg.com Universal Coders www.universalcoders.com

Education/Credentials
Bachelors in Computer engineering from COMSATS Institute of Information Technology (now COMSATS University)

©2016 About.com. All rights reserved.