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";
[B]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";[/B]
echo "  </tr>\n";
echo "</table>";

}
?>
Member Avatar for fatihpiristine

if ($row[NonSmoking] = 1)

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

if ($row[NonSmoking] == 1)

try now

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?

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";

You are echoing you "code" a one big long string. Do this:

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, ';
}
echo "</td>\n";
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).

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.