Jump to content

Query problem


unknown101

Recommended Posts

 

Hi Guys,

 

Wondering if anyone could give me a hand..im pretty new to SQL so go easy ;)  I am trying to achieve the following (example):

 

- A user enters the model of a car (not the manufacturer)

 

- I then check through all the tables (each being different car makes) to see if the model is within the one of those tables.

 

- If the model is within one of those tables, all other models which are also found in that table are printed out.

 

I have tried various things but still no luck.. this is probably quite simple but gotta start somewhere!

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/99955-query-problem/
Share on other sites

Sorry guys I may have written that slightly wrong:)

 

Basically what im trying to achieve is to check an atrribute of the user input, I think a better way of explaining it may be through the following:

 

-The user enters a movie title (All movies are stored with title, year, genre, actors in the sql db)

 

-The movie title is then looked up in the db and the film genre is identified i.e. "Horror".

 

-All horror movies will be in a particular table, so I then went to output all other movies from the same table.

 

I think the previous post I missed the beginng process slightly,

 

Cheers

 

 

Link to comment
https://forums.phpfreaks.com/topic/99955-query-problem/#findComment-511132
Share on other sites

Having different tables for different genres was a bad idea. You might wish to consider altering your database design, perhaps after reading up on database normalization. The sticky in this forum would be a good place to start.

 

That said, you could achieve this with two separate queries - the first to find the genre and the second to select everything from the relevant table. To the best of my knowledge, you can't achieve this in a single query.

Link to comment
https://forums.phpfreaks.com/topic/99955-query-problem/#findComment-511137
Share on other sites

Ah bummer, I kind of see what your saying now after reading that sticky..

 

Please could you give me a hand with the normalisation (as this is my first attempt:)

 

I have the following details to be stored..

 

-Artist

-Track

-Album

-Year

-Genre

 

From this ive come up with..

 

Table 1

Artist ID  ||   Artist   ||  Genre

 

Table 2

Artist ID || Album ID || Album || Year

 

Table 3

TrackID  || Track || Album ID

 

Any help appreciated..cheers

 

Link to comment
https://forums.phpfreaks.com/topic/99955-query-problem/#findComment-511232
Share on other sites

Thanks for that, so now i guess im back to the first question:)

 

So once I take the user input say.. $userSearch,

 

I then use this to form my first query i.e

 

SELECT Genre from TABLE1 where artist=$userSearch

 

So now I have the genre from that artist, but how can I then store this genre in a variable so I can use it in further functions?

 

Cheers

 

Link to comment
https://forums.phpfreaks.com/topic/99955-query-problem/#findComment-511287
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.