Jump to content

Displaying an image based on a DB value


Ross77

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.