Monday 15 March 2010

php - Mysql design for "favorites" entity -


I have a PHP application to use MySQL as a store. This app offers many services (eg. Cruises for and Hotel) and I want to apply the Favorites

I do not understand how easy it is to make the cheapest way to have two different favorite tables for each service Have to build, or keep them all in the table, but Surrey way should I join to other tables in a query that is not sure.

For example: User A has two favorites: 1 hotel and 1 cruise, so the query will look something like this:

  at SELECT id..text? =? Revolution on the left join? =? WHERE user_id =? And (this is very important) language_id = 1  

Tables revolve as the revolutions and hotel IDs use the primary key, so you can assume that ID is not relevant in this case is.

Edit: Sorry, I was not very precise. Users would be able to choose favorites, hotels, etc. and would be able to book them later. I want to know what is the best way to go and whether it is possible to select them from a database from a query

Your preferred table should have a user ID, source table (code for cruise or hotel) and ID for cruise or hotel tables.

Then select with the union

  select ID, 'H', Hotel_Name, ... enter the favorite from the hotel .id = favorite.id and favorites on Correctype = 'H' where userID =? Union Select Id, 'C', Cruz_Name, ... Cruise from Favorite. Id = Favorite. Id Join Cruise and Favorite Correct Type = 'C' Where Usid =?  

When using a union, type, & amp; The column name should match up & amp; bottom. If necessary, you can clearly leave something blank or in another


No comments:

Post a Comment