Welcome, Guest. Please login or register.

Author Topic: MySQL / PHP Programming (was, what comes next)  (Read 3884 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline buzz

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 612
    • Show all replies
Re: (RFD) Which would you prefer next?
« on: June 11, 2009, 01:24:36 PM »
Quote from: motorollin;510551
then the solution would be returned even if the user has just one of the requirements.

I don't know whether you can do this in (My)SQL or whether you would have to return all solutions to a given problem, then get PHP to do the checks. Any help appreciated :)

You can do it in sql. (generally) if you ever have a problem where you think you need to get lots of results and process in php, then the db design is probably not quite right or you need to rethink the query.

in your case you can alias the requirements table.

requirements B,
requirements C,

and join against it also.
 

Offline buzz

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 612
    • Show all replies
Re: (RFD) Which would you prefer next?
« Reply #1 on: June 11, 2009, 01:42:26 PM »
Quote from: motorollin;510583
Would that do the trick?


Not sure what this means, so I'l read about joining in SQL. I've heard of it, but never used it.

almost but you need to join the C table. You may have only heard of joins but you are already using them

AND B.solution_id = A.solution_id

is a join (implicit)

so join the C table also to A

I recommend some reading up a bit of sql and database design. will save time later on not making mistakes early on in your schema.
« Last Edit: June 11, 2009, 01:44:43 PM by buzz »
 

Offline buzz

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 612
    • Show all replies
Re: (RFD) Which would you prefer next?
« Reply #2 on: June 11, 2009, 02:40:53 PM »
Quote from: motorollin;510589
Could you give me an example of a situation where this might happen? Surely the worst case scenario is that no records are returned?


well say you had facilities at a park and you wanted to match all parks with certain facilities, you could use this and it wouldn't be a huge problem as the facilities table would never be that big etc, but if you had many thousands of facilities and a user chose 1 thousand to match from you would have a thousand joins and that just isnt going to work well. so in that case you would need to rethink how you will store/structure the data and so on.