943,846 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 690
  • PHP RSS
Oct 30th, 2008
0

How to display list of facilities

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gordo58 is offline Offline
11 posts
since Oct 2008
Oct 30th, 2008
0

Re: How to display list of facilities

if ($row[NonSmoking] = 1)

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

if ($row[NonSmoking] == 1)

try now
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Oct 30th, 2008
0

Re: How to display list of facilities

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gordo58 is offline Offline
11 posts
since Oct 2008
Oct 30th, 2008
0

Re: How to display list of facilities

php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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).
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 31st, 2008
0

Re: How to display list of facilities

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gordo58 is offline Offline
11 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: help
Next Thread in PHP Forum Timeline: text from database not displaying properly





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC