| | |
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
Views: 565 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube





