| | |
How to display list of facilities
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Oct 2008
Posts: 8
Reputation:
Solved Threads: 0
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?
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?
php Syntax (Toggle Plain Text)
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:
php Syntax (Toggle Plain Text)
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). ★ "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.
★ 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.
![]() |
Similar Threads
- IBM X20 LCD Bulb (Monitors, Displays and Video Cards)
- Linked List Problem (C++)
- Array and Switch issues (C++)
- To create contact manager using doubly linked list(c++) (C++)
- Audio Website Testimonial (Promotion and Marketing Plans)
Other Threads in the PHP Forum
- Previous Thread: Retrieving image path in MySQL! Help :)
- Next Thread: text from database not displaying properly
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue phpmyadmin problem query radio random recourse recursion remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





