How to display list of facilities

Thread Solved

Join Date: Oct 2008
Posts: 8
Reputation: gordo58 is an unknown quantity at this point 
Solved Threads: 0
gordo58 gordo58 is offline Offline
Newbie Poster

How to display list of facilities

 
0
  #1
Oct 30th, 2008
Hi,

I'm trying to list facilities available for a particular hotel horizontally, separated by a comma, within the <td> element of a table.

The facilities are type ENUM and have a value of '1' if available and '0' if not.
NonSmoking, AirCon and Restaurant are field names in the table (There is the possibility of up to 40 facilities to be displayed)

Any suggestion what I'm doing wrong? The code works apart from the bold section.

Thanks.

<?php
include 'connect.php';

// Execute the SQL query and return records

$result = mysql_query("SELECT * FROM tablename WHERE id = 1234");

while ($row = mysql_fetch_array($result)) {
echo "<table width=\"75%\" align=\"center\" cellpadding=\"0\"  cellspacing=\"2\">\n";
echo "  <tr>\n";
echo "    <td class=\"hotelinfohead\">Facilities</td>\n";
echo "  </tr>\n";
echo "  <tr>\n";
echo "    <td class=\"hotelinfotext\">
if ($row[NonSmoking] = 1) {
echo 'Non smoking rooms available, ';
}
if ($row[AirCon] = 1) {
echo 'Air conditioning, ';
}
if ($row[Restaurant] = 1) {
echo 'Restaurant, ';
}
</td>\n";
echo "  </tr>\n";
echo "</table>";

}
?>
Last edited by gordo58; Oct 30th, 2008 at 4:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 271
Reputation: fatihpiristine has a little shameless behaviour in the past 
Solved Threads: 16
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: How to display list of facilities

 
0
  #2
Oct 30th, 2008
if ($row[NonSmoking] = 1)

this will always return true.. you are doing assignment here use double equal signs

if ($row[NonSmoking] == 1)

try now
Do a favour, leave me alone
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: gordo58 is an unknown quantity at this point 
Solved Threads: 0
gordo58 gordo58 is offline Offline
Newbie Poster

Re: How to display list of facilities

 
0
  #3
Oct 30th, 2008
Hi,

Thanks for the reply. Your answer does now pull across the correct information.

I am still however having problems with displaying the information.

I can display the results outwith a table but as soon as I put the code into a <td> it prints out all the code. Am I doing something really dumb or is it not possible to have if conditions within a table?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: How to display list of facilities

 
0
  #4
Oct 30th, 2008
  1. echo " </tr>\n";
  2. echo " <tr>\n";
  3. echo " <td class=\"hotelinfotext\">
  4. if ($row[NonSmoking] == 1) {
  5. echo 'Non smoking rooms available, ';
  6. }
  7. if ($row[AirCon] == 1) {
  8. echo 'Air conditioning, ';
  9. }
  10. if ($row[Restaurant] == 1) {
  11. echo 'Restaurant, ';
  12. }
  13. </td>\n";
  14. echo " </tr>\n";

You are echoing you "code" a one big long string. Do this:
  1. echo " </tr>\n";
  2. echo " <tr>\n";
  3. echo " <td class=\"hotelinfotext\">";
  4. if ($row[NonSmoking] = 1) {
  5. echo 'Non smoking rooms available, ';
  6. }
  7. if ($row[AirCon] = 1) {
  8. echo 'Air conditioning, ';
  9. }
  10. if ($row[Restaurant] = 1) {
  11. echo 'Restaurant, ';
  12. }
  13. echo "</td>\n";
  14. echo " </tr>\n";

BTW, is it actually legal to call $array[name] instead of $array['name'] ? I was under the impression that you needed quotes (going off examples I have seen. That's how I learnt).
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: gordo58 is an unknown quantity at this point 
Solved Threads: 0
gordo58 gordo58 is offline Offline
Newbie Poster

Re: How to display list of facilities

 
0
  #5
Oct 31st, 2008
Hi,

Thanks for your help. Everything is working fine now.

I'm not sure about the array with 's in the name. The tutotial I used did not use them and seems to work ok.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC