Ross77 Posted July 3, 2012 Share Posted July 3, 2012 Hi, I am trying to write a bit of code for a hotel website that will display facilities at the hotel such as restaurant, gym, disabled access and so on. I wanted to write some php that will basically "talk" to the database and see if the location in question has any of those facilities. So the table will have columns for each facility and then I would put a 1 or 0 in each column with a 1 meaning the hotel has a gym for example and a 0 meaning they don't. And if there's a 1 in the DB then the webpage will display the corresponding image. I used this code to call in the hotel's email address from the same DB: <?php $my_data = $wpdb->get_var( $wpdb->prepare( " SELECT address FROM wp_email WHERE id = '$p' " ) ); echo "<p>Our email address is <a href='mailto:$my_data'>$my_data</a></p>"; ?> I was hoping to alter the code above to achieve the result but I'm not sure how to do it. If anyone has any suggestions or ideas then I'm all ears. And if I've explained myself badly then let me know :-) Thanks, Ross Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2012 Share Posted July 3, 2012 Don't create columns for each facility, put them in a separate table with a row for each hotel's facility. hotel hotel_facility facility +-----------+ +--------------+ +-------------+ | id | | hotel_id | | id | | name | | facility_id | | descrip | | email | +--------------+ +-------------+ +-----------+ 1 Grand 1 | A A Restaurant 2 Savoy 1 | C B Spa 2 | A C Gym 2 | B 2 | C Now, if a hotel comes along with a new facility, you don't have redesign your table structure, just add new facility and record the hotels facilities 3 Boodles 3 | A D - Dogs allowed 3 | B 3 | D Quote Link to comment Share on other sites More sharing options...
Ross77 Posted July 3, 2012 Author Share Posted July 3, 2012 You're a superstar I appreciate the help! Let me go and give it whirl and I hopefully be telling it worked later! Thanks again, Ross Quote Link to comment Share on other sites More sharing options...
sloth456 Posted July 3, 2012 Share Posted July 3, 2012 The code you posted looks like you're using a class to access the database. Are you by any chance doing this with wordpress? I'm asking because we might need to know how the class is written in order to know how to use it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.