473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

help with foreach loop that builds a recordset access database

So as everyone else I am new to PHP and I have been trying to create an amenity page for a B&B. I need folk to be able to select checkboxes and it fetches the info from the database.
I posted the checkbox list to the ampage and now I need to search the database for the matching records.
so I know I need to write
Expand|Select|Wrap|Line Numbers
  1. foreach ($_POST['amenty'] as $value) {
  2.         $breakfast = what
  3.         $bbq
  4.         $kitchenette
  5. }
can someone check to see if I wrote my data base correctly

AMENITY CHECKBOXES
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title>B and B Association of San Juan Amenities Page</title>
  6. <link href="scripts/main.css" rel="stylesheet" type="text/css" />
  7. </head>
  8.  
  9. <body>
  10.     <div id="mainContent" >
  11.         <h1 class="headersTitles">Bed and Breakfast Amenities</h1>
  12.         <div id="mainArticle">
  13.             <p>&nbsp;</p>
  14.             <p class="mainTextLight">Check the Amenities you are interested in and we will show you the Inns with the features you desire.</p>
  15. <p class="innTitleLightLeft">&nbsp;</p>
  16.             <p class="innTitleLightLeft">&nbsp;</p>
  17.             <form id="form1" name="form1" method="post" action="ampage.php">
  18.                 <div id="amenities1">
  19.                     <p>
  20.                         <input name="amenity[]" type="checkbox" id="amenity_breakfast" value="breakfast" />
  21.                         <label for="">Full Breakfast</label>
  22.                     </p>
  23.                     <p>&nbsp;</p>
  24.                     <p>
  25.                         <input name="amenity[]" type="checkbox" id="amenity_bbq" value="bbq" />
  26.                         <label for="amenity[]">BBQ Available</label>
  27.                     </p>
  28.                     <p>&nbsp;</p>
  29.                     <p>
  30.                         <input name="amenity[]" type="checkbox" id="amenity_kitchenette" value="kitchenette" />
  31.                         <label for="amenity[]">Kitchenette</label>
  32.                     </p>
  33.                     <p>&nbsp;</p>
  34.                     <p>
  35.                         <input name="amenity[]" type="checkbox" id="amenity_fireplace" value="fireplace" />
  36.                         <label for="amenity[]">Fireplace</label>
  37.                     </p>
  38.                     <p>&nbsp;</p>
  39.                     <p>
  40.                         <input name="amenity[]" type="checkbox" id="amenity_internet" value="internet" />
  41.                         <label for="amenity[]">Internet Access/ WiFi</label>
  42.                     </p>
  43.                     <p>&nbsp;</p>
  44.                     <p>
  45.                         <input name="amenity[]" type="checkbox" id="amenity_tv" value="tv" />
  46.                         <label for="amenity[]">Television</label>
  47.                     </p>
  48.                 </div>
  49.                 <div id="amenities2">
  50.                     <p>
  51.                         <input name="amenity[]" type="checkbox" id="amenity_dvd" value="dvd" />
  52.                         <label for="amenity[]">DVD / VCR</label>
  53.                     </p>
  54.                     <p>&nbsp;</p>
  55.                     <p>
  56.                         <input name="amenity[]" type="checkbox" id="amenity_video" value="video" />
  57.                         <label for="amenity[]">Videos</label>
  58.                     </p>
  59.                     <p>&nbsp;</p>
  60.                     <p>
  61.                         <input name="amenity[]" type="checkbox" id="amenity_bath" value="bath" />
  62.                         <label for="amenity[]">Private Bath</label>
  63.                     </p>
  64.                     <p>&nbsp;</p>
  65.                     <p>
  66.                         <input name="amenity[]" type="checkbox" id="amenity_jacuzzi" value="jacuzzi" />
  67.                         <label for="amenity[]">Jacuzzi / Jet Tub</label>
  68.                     </p>
  69.                     <p>&nbsp;</p>
  70.                     <p>
  71.                         <input name="amenity[]" type="checkbox" id="amenity_hotub" value="hotub" />
  72.                         <label for="amenity[]">Hot Tub</label>
  73.                     </p>
  74.                 </div>
  75.                 <div id="amenities3">
  76.                     <p>
  77.                         <input name="amenity[]" type="checkbox" id="amenity_massage" value="massage" />
  78.                         <label for="amenity[]">Massage Available</label>
  79.                     </p>
  80.                     <p>&nbsp;</p>
  81.                     <p>
  82.                         <input name="amenity[]" type="checkbox" id="amenity_handicap" value="handicap" />
  83.                         <label for="amenity[]">Handicapped Access</label>
  84.                     </p>
  85.                     <p>&nbsp;</p>
  86.                     <p>
  87.                         <input name="amenity[]" type="checkbox" id="amenity_child" value="child" />
  88.                         <label for="amenity[]">Child Friendly</label>
  89.                     </p>
  90.                     <p>&nbsp;</p>
  91.                     <p>
  92.                         <input name="amenity[]" type="checkbox" id="amenity_pickup" value="pickup" />
  93.                         <label for="amenity[]">Pickup Services</label>
  94.                     </p>
  95.                     <p>&nbsp;</p>
  96.                     <p>
  97.                         <input name="amenity[]" type="checkbox" id="amenity_pet" value="pet" />
  98.                         <label for="amenity[]">Pet Friendly</label>
  99.                     </p>
  100.                 </div>
  101.                 <p>&nbsp;</p>
  102.                 <p>&nbsp;</p>
  103.                 <p>&nbsp;</p>
  104.                 <p>&nbsp;</p>
  105.                 <p>&nbsp;</p>
  106.                 <p>&nbsp;</p>
  107.                 <p>&nbsp;</p>
  108.                 <p>&nbsp;</p>
  109.                 <p>&nbsp;</p>
  110.                 <p>&nbsp;</p>
  111.                 <p>&nbsp;</p>
  112.                 <p>&nbsp;</p>
  113.                 <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                </p>
  114.                 <p>
  115.                     <input name="Search" type="submit" value="Search" tabindex="170"/>
  116.                     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  117.                 <input name="start"  type="submit" value="Start Over" tabindex="180" />
  118.                 </p>
  119.             </form>
  120.         </div>
  121.     </div>
  122. </body>
  123. </html>

AMPAGE
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>checkboxes</title>
  5. <link href="scripts/main.css" rel="stylesheet" type="text/css" />
  6. <style type="text/css"></style>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <?php
  12. //not sure what I am doing here I know I need to create a loop with a foreach
  13. foreach ($_POST['amenity'] as $value) {
  14. $breakfast;
  15. }
  16.  
  17. mysql_connect($read, $write);
  18. mysql_select_db($write) or die("Unable to select database");
  19.  
  20. $select_query="select am_id from amenities" . $POST;
  21.  
  22.  
  23.  
  24. ?>
  25. <div id="mainArticle">
  26. <?php 
  27. // here are the image and text that needs to come back for each inn 
  28. $innID=mysql_result($result, "am_id");
  29. $image1=mysql_result ($result, $row = "image1");
  30. ?>
  31.     <div id="mainArticleInn3">
  32.                 <div id="inn3a"><a href = "<?php echo $row['url']; ?>" target="_blank"><img src="innpg/<?php echo $row['image1']; ?>" width="200" height="150" /></a></div>
  33.                 <div class="lightText" id="innText3"> 
  34.                     <p class="innTitleLight"><a href="<?php echo $row['url']; ?>" target = "_blank"> <?php echo $row['bbname']; ?></a></p>
  35.                     <p class="innPhoneLight"><?php echo $row['phone']; ?></p>
  36.                     <p class="innPhoneLight"><?php echo $row['tollFree']; ?></p>
  37.                     <p class="innPhoneLight"><?php echo $row['fax']; ?></p>
  38.                     <p class="innWebLight"><a href = "<?php echo $row['url']; ?>" target="_blank"><?php echo $row['web'] ?></a></p>
  39.                     <p class="innWebLight"><a href="<?php echo $row['emailL']; ?>" target="_blank"><?php echo $row['email'] ?></a></p>
  40. <div id="dateMap3"><a href="http://bytes.com/submit/calendar/calendar.html"><img src="logoMB /checkDateW.gif" alt="Check Date" width="60" height="40" align="left" /></a><a href="<?php echo $row['map']; ?>"><img src="logoMB /showOnMapW.gif" alt="Show on Map" width="60" height="40" align="right" /></a></div>
  41.                 </div>
  42.                 <div id="inn3b"><a href="<?php echo $row['url']; ?>" target="_blank"><img src="innpg/<?php echo $row['image2']; ?>" width="200" height="150" /></a></div>
  43.                 <div id="innRating3"><img src="logoMB /<?php echo $row['logo1']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo2']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo3']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo4']; ?>" width="60" height="55" /></div>
  44.         <div class="InformationTextLight" id="innMainText3"><?php echo $row['description']; ?>
  45.         </div>
  46.                 <p class="lightText">&nbsp;</p>
  47.     </div>
  48.  
  49. <form id="form1" name="form1" method="post" action="">
  50.     <input type="submit" name="start" id="start" value="Start Over" />
  51. </form>
  52. </div>
  53. </body>
  54. </html>

DATABASE
Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.2.5
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Host: localhost
  6. -- Generation Time: Mar 11, 2011 at 04:59 PM
  7. -- Server version: 5.1.44
  8. -- PHP Version: 5.3.2
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12.  
  13. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  14. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  15. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  16. /*!40101 SET NAMES utf8 */;
  17.  
  18. --
  19. -- Database: `sjibb_test`
  20. --
  21.  
  22. -- --------------------------------------------------------
  23.  
  24. --
  25. -- Table structure for table `amenities`
  26. --
  27.  
  28. CREATE TABLE `amenities` (
  29.   `am_id` int(11) NOT NULL,
  30.   `image1` varchar(50) NOT NULL,
  31.   `bbName` varchar(50) NOT NULL,
  32.   `phone` varchar(20) NOT NULL,
  33.   `tollFree` varchar(20) NOT NULL,
  34.   `fax` varchar(20) NOT NULL,
  35.   `web` varchar(50) NOT NULL,
  36.   `url` varchar(50) NOT NULL,
  37.   `email` varchar(50) NOT NULL,
  38.   `emailL` varchar(50) NOT NULL,
  39.   `map` varchar(50) NOT NULL,
  40.   `image2` varchar(50) NOT NULL,
  41.   `logo1` varchar(50) NOT NULL,
  42.   `logo2` varchar(50) NOT NULL,
  43.   `logo3` varchar(50) NOT NULL,
  44.   `logo4` varchar(50) NOT NULL,
  45.   `description` varchar(4096) NOT NULL,
  46.   `breakfast` varchar(4) NOT NULL,
  47.   `bbq` varchar(4) NOT NULL,
  48.   `kitchenette` varchar(4) NOT NULL,
  49.   `fireplace` varchar(4) NOT NULL,
  50.   `internet` varchar(4) NOT NULL,
  51.   `tv` varchar(4) NOT NULL,
  52.   `dvd` varchar(4) NOT NULL,
  53.   `video` varchar(4) NOT NULL,
  54.   `bath` varchar(4) NOT NULL,
  55.   `jacuzzi` varchar(4) NOT NULL,
  56.   `hotub` varchar(4) NOT NULL,
  57.   `massage` varchar(4) NOT NULL,
  58.   `handicap` varchar(4) NOT NULL,
  59.   `child` varchar(4) NOT NULL,
  60.   `pickup` varchar(4) NOT NULL,
  61.   `pet` varchar(4) NOT NULL,
  62.   PRIMARY KEY (`am_id`)
  63. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
  64.  
  65. --
  66. -- Dumping data for table `amenities`
  67. --
  68.  
  69. INSERT INTO `amenities` VALUES(1, '../imagesMB/innpg/argyle.jpg', 'ARGYLE HOUSE', '360-378-4084', '800-624-3459', '', 'www.argylehouse.net', 'http://www.argylehouse.net', 'info@argylehouse.net', 'info@argylehouse.net', '../maps/Argyle.html', '../imagesMB/innpg/argyle1.jpg', '../imagesMB/logoMB/threedoor.gif', '', '', '', 'Enjoy the charm and character of this 1910-vintage Craftsman located only two blocks from downtown and a short walk from the ferry. Nestled on beautiful grounds to ensure the peace and quiet of a country setting. Comfortable well appointed rooms with in-room TV/DVD, plus hot tub, delicious hot breakfast every day, and wireless Internet access. Children and dogs are welcome here! ', 'yes', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'yes', 'yes');
  70. INSERT INTO `amenities` VALUES(2, '../imagesMB/innpg/dragonfly.jpg', 'DRAGONFLY INN', '360-378-4280', '877-378-4280', '360-378-1392', 'www.thedragonflyinn.com', 'http://www.thedragonflyinn.com', 'host@thedragonflyinn.com', 'host@thedragonflyinn.com', '../maps/dragonfly.html', '../imagesMB/innpg/dragonfly1.jpg', '../imagesMB/logoMB/aaa3D.gif', '../imagesMB/logoMB/threedoor.gif', '', '', 'A unique,Japanese-inspired bed and breakfast, promising a secluded, romantic get away on 15 acres of unspoiled Pacific Northwestern woods. Our tranquil rooms include a queen-size bed,Free Wi-Fi,satellite TV/DVD, pulsating 2-headed shower,oversized 2-person air massage tub, and private patio. Dragonfly''s sumptuous Asian fusion gourmet breakfasts and afternoon treats blend the comfortable and the exotic.  No children or pets. ', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'no');
  71. INSERT INTO `amenities` VALUES(3, '../imagesMB/innpg/harrison.jpg', 'HARRISON HOUSE', '360-378-3587', '800-407-7933', '360-378-2270 FAX', 'www.harrisonhousesuites.com', 'http://www.harrisonhousesuites.com', 'innkeeper@harrisonhouse.com', 'innkeeper@harrisonhouse.com', '../maps/Harrison.html', '../imagesMB/innpg/harrison1.jpg', '../imagesMB/logoMB/threedoor.gif', '../imagesMB/logoMB/nwBest.gif', '../imagesMB/logoMB/kiss2.gif', '../imagesMB/logoMB/mobil.gif', 'A hilltop retreat one block from the ferry landing. Fully furnished private suites with kitchens, harbor views, fireplaces, and private hot tubs - sleep two to ten in comfort. Gourmet breakfast, afternoon time, and dinner delivered to your suite or in our private caf√©. Retreats, family reunions, and weddings. Pet friendly. NW Best Places. Peoples Choice Awards. One of 40 inns throughout the state, chosen to be featured in Special Places. ', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'yes');
  72. INSERT INTO `amenities` VALUES(4, '../imagesMB/innpg/hillside.jpg', 'HILLSIDE HOUSE', '360-378-4730', '800-232-4730', '360-378-4715 FAX', 'www.hillsidehouse.com', 'http://www.hillsidehouse.com', 'info@hillsidehouse.com', 'info@hillsidehouse.com', '../maps/Hillside.html', '../imagesMB/innpg/hillside1.jpg', '../imagesMB/logoMB/aaa3D.gif', '../imagesMB/logoMB/threedoor.gif', '../imagesMB/logoMB/kiss2.gif', '../imagesMB/logoMB/mobil.gif', 'Enjoy views of snowcapped Mt. Baker over the blue waters of Friday Harbor from the spacious deck of this contemporary-style inn. Located just 3/4 of a mile from ferries and airport. Our famous homemade Banana Chocolate Chip cookies are always within easy reach. We are triple diamond rated by AAA and triple star rated by Mobil. WIFI Internet access. ', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no');
  73. INSERT INTO `amenities` VALUES(5, '../imagesMB/innpg/intothewoods.jpg', 'INN TO THE WOODS', '360-378-9501', '888-292-9502', '', 'www.inntothewoods.com', 'http://www.inntothewoods.com', 'inntothewoods@rockisland.com', 'inntothewoods@rockisland.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/intothewoods1.jpg', '../imagesMB/logoMB/threedoor.gif', '', '', '', 'Luxurious amenities and furnishings in this new bed breakfast. Suite includes outdoor private deck with Jacuzzi spa, interior Jacuzzi tub & separate shower. All rooms have private phones, VCR and satellite TV with cordless stereo headphones, guest robes, hair dryers & chocates. Comfortable great room with outdoor deck overlooking lake, Web access, books, magazines, games, movies. Afternoon tea daily. Guest Quarters separated from Innkeeper quarters.', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'yes', 'no');
  74. INSERT INTO `amenities` VALUES(6, '../imagesMB/innpg/kirk.jpg', 'KIRK HOUSE', '360-378-3757', '800-639-2762', '', 'www.kirkhouse.net', 'http://www.kirkhouse.net', 'info@kirkhouse.net', 'info@kirkhouse.net', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/kirk1.jpg', '', '', '', '', 'Historic Craftsman style home built in 1907 with twelve foot ceilings, wood-wrapped arched doorways, leaded glass and granite fireplaces and also modern conveniences like wireless internet access and TV/DVD in each room. Four rooms, each with private bath and private entry. Morning breakfast and afternoon snacks. Quiet in-town location with an easy walk to shops and restaurants. ', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'no');
  75. INSERT INTO `amenities` VALUES(7, '../imagesMB/innpg/olympic.jpg', 'OLYMPIC LIGHTS', '360-378-3186', '888-211-6195', '360-378-2097', 'www.olympiclights.com', 'http://www.olympic.com', 'olympiclights@rockisland.com', 'olympiclights@rockisland.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/olympic1.jpg', '', '', '', '', '1895 Victorian Farmhouse located on the sunny south end, near American Camp (National Park). Peaceful meadow setting on 5 acres with panoramic views of the sea and the Olympic Mountain Range. 4 rooms with private baths - two with water views. Full breakfast served with eggs from our resident hens. 5 1/2 miles from ferry.', 'yes', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'no', 'no', 'no');
  76. INSERT INTO `amenities` VALUES(8, '../imagesMB/innpg/slowSeasons.jpg', 'WHARFSIDE B & B', '', '360-378-5661', '', 'www.slowseason.com', 'http://www.slowseason.com', 'wharfside@rockisland.com', 'wharfside@rockisland.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/slowSeasons1.jpg', '', '', '', '', 'Experience Friday Harbor afloat, aboard an enchanting 60 ft. Ketch rigged motor sailor in the tradition of European floating Inns. This elegant vessel has two spacious private romantic staterooms, queen size beds, DVD, WiFi and full gourmet breakfast. Stay with us for your special occasions and experience the islands with a morning cruise to Seal Rock or enjoy relaxing on deck with a breathtaking view of Friday Harbor''s waterfront.', 'yes', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no');
  77. INSERT INTO `amenities` VALUES(9, '../imagesMB/innpg/stateInn.jpg', 'STATES INN AND RANCH', '360-378-6240', '866-602-2737', '360-378-6241 FAX', 'www.stateinn.com', 'http://www.stateinn.com', 'ranch@stateinn.com', 'ranch@stateinn.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/statesInn1.jpg', '../imagesMB/logoMB/aaa3D.gif', '../imagesMB/logoMB/threedoor.gif', '../imagesMB/logoMB/kiss2.gif', '', 'Rooms and suites on a 60 acre working ranch. All private baths. Feed our sheep and alpacas; visit our chickens. Scratch breakfast with local foods from local farms, eggs from our own pasture raised eggs and our own award-winning jams and jellies. Free WiFi. Comfortable common areas. We welcome reunions and family gatherings. Handicapped units available. Country store features gifts, homemade lunch, fresh bread and local ice cream.', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'yes', 'no');
  78. INSERT INTO `amenities` VALUES(10, '../imagesMB/innpg/trumpeter.jpg', 'TRUMPETER INN', '360-378-3884', '800-826-7926', '360-378-8235 FAX', 'www.trumpeterinn.com', 'http://www.trumpeterinn.com', 'swan@trumpeterinn.com', 'swan@trumpeterinn.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/trumpeter1.jpg', '../imagesMB/logoMB/aaa3D.gif', '../imagesMB/logoMB/threedoor.gif', '../imagesMB/logoMB/kiss2.gif', '', 'Contemporarily furnished Inn on 5 serene acres. Offering more than just beautiful bedrooms & gourmet breakfasts. Personalized vacation planning & WIFI. Pick‚Ä¢up service at ferry/airport. On site private massage studio. Gardens for reading, bird-watching or just relaxing. Soaking tub set under the stars. Two separate den to read or watch TV & movies. Private decks for sipping morning coffee or afternoon cocktails.', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes');
  79. INSERT INTO `amenities` VALUES(11, '../imagesMB/innpg/tucker.jpg', 'TUCKER HOUSE', '360-378-2783', '800-965-0123', '360-378-2270', 'www.tuckerhouse.com', 'http://www.tuckerhouse.com', 'reservations@tuckerhouse.com', 'reservations@tuckerhouse.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/tucker1.jpg', '../imagesMB/logoMB/nwBest.gif', '../imagesMB/logoMB/kiss2.gif', '../imagesMB/logoMB/bellHop.gif', '', 'This newly-renovated 1898 Victorian inn with cottages is nestled in a quiet Friday Harbor neighborhood, just 2 blocks from the ferry landing and center of town. All rooms feature private baths, TV/VCRs and a full breakfast. Some rooms and suites have 2 person Jacuzzi tubs, balconies, fire places, kitchenettes and private entrances. Families and pets are welcome in our cottages. Excellent amenities and rates. One of 40 Inns in the state selected to be in the Special PlacesBook. ', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes');
  80. INSERT INTO `amenities` VALUES(12, '../imagesMB/innpg/wildwood.jpg', 'WILDWOOD MANOR', '360-378-3447', '877-298-1144', '360-378-6095', 'www.wildwoodmanor.com', 'http://www.wildwoodmanor.com', 'stay@wildwoodmanor.com', 'stay@wildwoodmanor.com', '../imagesMB/logoMB/showOnMapW.gif', '../imagesMB/innpg/wildwood1.jpg', '../imagesMB/logoMB/threedoor.gif', '', '', '', 'Wildwood Manor is an elegant Queen Anne-style home with breathtaking views of the water and forest. Our eleven tranquil acres feature beautiful gardens and wooded walking paths. Four beautifully appointed rooms with private baths, TV, DVD, and fine amenities. Our three course breakfasts will entice you and get your day off to a delicious start. Endless snacks and refreshments.', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no', 'no');
  81.  
Mar 12 '11 #1
16 4075
Dormilich
8,658 Expert Mod 8TB
your database code definitely won’t work.

- foreach(): I don’t know either what you want there
- line #20: inserts the string "Array". not sure what that’s supposed to do.
- mysql_connect(): a) wrong function (outdated), b) wrong parameter set, please refer to the manual.
Mar 12 '11 #2
thank you for your reply
what I need is if you go on the amenities page and check breakfast, pickup, tv and child
The ampage will bring up the inns that have those amenities
so the harrison house, trumpeter inn and argyle house return as a result
does this make sense
Mar 12 '11 #3
web site is at
http://mossgraphics.net/TestSite/ame.../amenities.php
ampage is not up yet
I am trying to create it with the mySQL
so all the information will show up on the page
Mar 12 '11 #4
Dormilich
8,658 Expert Mod 8TB
what you need for your query is a WHERE clause, e.g.
Expand|Select|Wrap|Line Numbers
  1. // find all amenities with internet
  2. $select_query = "SELECT `am_id` FROM `amenities` WHERE `internet` = 1";
additionally, I’d use the ENUM type for those fields (either they have it or they don’t) and you can move all of the descriptive fields (fax, mail, phone, address) to a new table.
Mar 13 '11 #5
Thank you soooooo much I will get on it right away. This weekend I was in a remote area but I downloaded the php manual and read some of it. Thanks again for all the help.
Mar 15 '11 #6
oh boy I thought I was thinking like you but I got lost again.
For the good news I did separate the tables and was able to populate the fields of name, fax, mail, phone, address. I am lost with the amenities again, I created a new table, not sure which one to use now. I feel like an idiot. I am an artist and this does not compute. My right brain is getting a workout.

FOR THE GOOD NEWS
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. //Connect
  3. $link = mysql_connect('localhost', '***', '***');
  4. if (!$link) {
  5.     die('Could not connect: ' . mysql_error());
  6. }
  7. $db_selected = mysql_select_db('***', $link);
  8. if (!$db_selected) {
  9.     die('Could not select database: ' . mysql_error());
  10. }
  11. $query = 'SELECT * FROM inns';
  12. $result = mysql_query($query);
  13. if (!$result) {
  14.     die('Query failed: ' . mysql_error());
  15. }
  16. ?>
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19. <head>
  20. <title>checkboxes</title>
  21. <link href="scripts/main.css" rel="stylesheet" type="text/css" />
  22. <style type="text/css"></style>
  23. </head>
  24.  
  25. <body>
  26. <div id="mainArticle">
  27.     <div id="mainArticleInn3">
  28.     <?php
  29.         //populates information fields
  30.         for ($i = 0; $i <= mysql_num_rows($result) -1;  $i++) {
  31.             if (!mysql_data_seek($result, $i)) {
  32.                 echo "Cannot seek to row $i: " . mysql_error() . "\n";
  33.                 continue;
  34.                 }
  35.  
  36.             if (!($row = mysql_fetch_assoc($result))) {
  37.                     continue;
  38.                 }
  39.  
  40.  
  41.         }
  42.  
  43.         mysql_free_result($result);
  44.  
  45. ?>
  46.                 <div id="inn3a"><a href = "<?php echo $row['url']; ?>" target="_blank"><img src="innpg/<?php echo $row['image1']; ?>" width="200" height="150" /></a></div>
  47.                 <div class="lightText" id="innText3"> 
  48.                     <p class="innTitleLight"><a href="<?php echo $row['url']; ?>" target = "_blank"> <?php echo $row['bbName']; ?></a></p>
  49.                     <p class="innPhoneLight"><?php echo $row['phone']; ?></p>
  50.                     <p class="innPhoneLight"><?php echo $row['tollFree']; ?></p>
  51.                     <p class="innPhoneLight"><?php echo $row['fax']; ?></p>
  52.                     <p class="innWebLight"><a href = "<?php echo $row['url']; ?>" target="_blank"><?php echo $row['web'] ?></a></p>
  53.                     <p class="innWebLight"><a href="<?php echo $row['emailL']; ?>" target="_blank"><?php echo $row['email'] ?></a></p>
  54. <div id="dateMap3"><a href="http://bytes.com/topic/php/calendar/calendar.html"><img src="logoMB /checkDateW.gif" alt="Check Date" width="60" height="40" align="left" /></a><a href="<?php echo $row['map']; ?>"><img src="logoMB /showOnMapW.gif" alt="Show on Map" width="60" height="40" align="right" /></a></div>
  55.                 </div>
  56.                 <div id="inn3b"><a href="<?php echo $row['url']; ?>" target="_blank"><img src="innpg/<?php echo $row['image2']; ?>" width="200" height="150" /></a></div>
  57.                 <div id="innRating3"><img src="logoMB /<?php echo $row['logo1']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo2']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo3']; ?>" width="60" height="55" /><img src="logoMB /<?php echo $row['logo4']; ?>" width="60" height="55" /></div>
  58.         <div class="InformationTextLight" id="innMainText3"><?php echo $row['description']; ?>
  59.         </div>
  60.                 <p class="lightText">&nbsp;</p>
  61.     </div>
  62.  
  63. <form id="form1" name="form1" method="post" action="amenities.php">
  64.     <input type="submit" name="start" id="start" value="Start Over" />
  65. </form>
  66. </div>
  67. </body>
  68. </html>

HERE IS TABLE 1 where I played with ENUM and it didn't quite make sense, so I created table 2 down below. I am still working with it, but not sure which one to use

Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.2.5
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Host: localhost
  6. -- Generation Time: Mar 15, 2011 at 04:12 PM
  7. -- Server version: 5.1.44
  8. -- PHP Version: 5.3.2
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12.  
  13. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  14. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  15. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  16. /*!40101 SET NAMES utf8 */;
  17.  
  18. --
  19. -- Database: `sjibb_test`
  20. --
  21.  
  22. -- --------------------------------------------------------
  23.  
  24. --
  25. -- Table structure for table `amenities`
  26. --
  27.  
  28. CREATE TABLE `amenitites` (
  29.   `am_id` int(11) NOT NULL,
  30.   `bbName` enum('1','2','3','4','5','6','7','8','9','10','11','12') NOT NULL,
  31.   `breakfast` varchar(4) NOT NULL,
  32.   `bbq` varchar(4) NOT NULL,
  33.   `kitchenette` varchar(4) NOT NULL,
  34.   `fireplace` varchar(4) NOT NULL,
  35.   `internet` varchar(4) NOT NULL,
  36.   `tv` varchar(4) NOT NULL,
  37.   `dvd` varchar(4) NOT NULL,
  38.   `video` varchar(4) NOT NULL,
  39.   `bath` varchar(4) NOT NULL,
  40.   `jacuzzi` varchar(4) NOT NULL,
  41.   `hotub` varchar(4) NOT NULL,
  42.   `massage` varchar(4) NOT NULL,
  43.   `handicap` varchar(4) NOT NULL,
  44.   `child` varchar(4) NOT NULL,
  45.   `pickup` varchar(4) NOT NULL,
  46.   `pet` varchar(4) NOT NULL,
  47.   PRIMARY KEY (`am_id`)
  48. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  49.  
  50. --
  51. -- Dumping data for table `amenity_test`
  52. --
  53.  
  54. INSERT INTO `amenity_test` VALUES(1, '1', 'yes', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'yes', 'yes');
  55. INSERT INTO `amenity_test` VALUES(2, '2', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'no');
  56. INSERT INTO `amenity_test` VALUES(3, '3', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'yes');
  57. INSERT INTO `amenity_test` VALUES(4, '4', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no');
  58. INSERT INTO `amenity_test` VALUES(5, '5', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'yes', 'no');
  59. INSERT INTO `amenity_test` VALUES(6, '6', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'no', 'no', 'no', 'no');
  60. INSERT INTO `amenity_test` VALUES(7, '7', 'yes', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'no', 'no', 'no');
  61. INSERT INTO `amenity_test` VALUES(8, '8', 'yes', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 'yes', 'no', 'no', 'no', 'no', 'yes', 'no', 'no');
  62. INSERT INTO `amenity_test` VALUES(9, '9', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'yes', 'yes', 'no');
  63. INSERT INTO `amenity_test` VALUES(10, '10', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes');
  64. INSERT INTO `amenity_test` VALUES(11, '11', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes');
  65. INSERT INTO `amenity_test` VALUES(12, '12', 'yes', 'no', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no', 'no');
  66.  
THEN I THOUGHT OF CHANGING IT TO THIS is this wrong?
I made a row of inns and the columns are the amenities. Is this what you meant?
Expand|Select|Wrap|Line Numbers
  1. -- phpMyAdmin SQL Dump
  2. -- version 3.2.5
  3. -- http://www.phpmyadmin.net
  4. --
  5. -- Host: localhost
  6. -- Generation Time: Mar 15, 2011 at 04:00 PM
  7. -- Server version: 5.1.44
  8. -- PHP Version: 5.3.2
  9.  
  10. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
  11.  
  12.  
  13. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  14. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  15. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  16. /*!40101 SET NAMES utf8 */;
  17.  
  18. --
  19. -- Database: `sjibb_test`
  20. --
  21.  
  22. -- --------------------------------------------------------
  23.  
  24. --
  25. -- Table structure for table `amenities_test`
  26. --
  27.  
  28. CREATE TABLE `amenities_test` (
  29.   `am_id` int(11) NOT NULL AUTO_INCREMENT,
  30.   `argyle` varchar(20) NOT NULL,
  31.   `dragonfly` varchar(20) NOT NULL,
  32.   `harrison` varchar(20) NOT NULL,
  33.   `hillside` varchar(20) NOT NULL,
  34.   `intothewoods` varchar(20) NOT NULL,
  35.   `kirk` varchar(20) NOT NULL,
  36.   `olympic` varchar(20) NOT NULL,
  37.   `warfside` varchar(20) NOT NULL,
  38.   `states` varchar(20) NOT NULL,
  39.   `trumpeter` varchar(20) NOT NULL,
  40.   `tucker` varchar(20) NOT NULL,
  41.   `wildwood` varchar(20) NOT NULL,
  42.   PRIMARY KEY (`am_id`)
  43. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=54 ;
  44.  
  45. --
  46. -- Dumping data for table `amenities`
  47. --
  48.  
  49. INSERT INTO `amenities` VALUES(1, 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast', 'breakfast');
  50. INSERT INTO `amenities` VALUES(2, 'bbq', '', 'bbq', 'bbq', '', 'bbq', '', '', 'bbq', '', 'bbq', '');
  51. INSERT INTO `amenities` VALUES(3, '', '', 'kitchenette', '', '', '', '', '', 'kitchenette', '', 'kitchenette', '');
  52. INSERT INTO `amenities` VALUES(4, '', '', 'fireplace', 'fireplace', '', 'fireplace', 'fireplace', '', 'fireplace', 'fireplace', 'fireplace', 'fireplace');
  53. INSERT INTO `amenities` VALUES(5, 'internet', '', '', '', '', '', '', '', '', '', '', '');
  54. INSERT INTO `amenities` VALUES(6, 'tv', 'tv', 'tv', 'tv', '', 'tv', '', '', 'tv', 'tv', 'tv', 'tv');
  55. INSERT INTO `amenities` VALUES(7, 'dvd', 'dvd', 'dvd', 'dvd', '', 'dvd', '', '', 'dvd', 'dvd', 'dvd', 'dvd');
  56. INSERT INTO `amenities` VALUES(8, 'video', '', 'video', 'video', '', 'video', '', '', '', 'video', 'video', 'video');
  57. INSERT INTO `amenities` VALUES(9, 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath', 'bath');
  58. INSERT INTO `amenities` VALUES(10, '', 'jacuzzi', 'jacuzzi', 'jacuzzi', '', 'jacuzzi', '', '', '', '', 'jacuzzi', '');
  59. INSERT INTO `amenities` VALUES(11, 'hotub', '', 'hotub', '', '', '', '', '', '', 'hotub', 'hotub', '');
  60. INSERT INTO `amenities` VALUES(12, 'massage', '', 'massage', '', '', '', '', '', '', 'massage', 'massage', 'massage');
  61. INSERT INTO `amenities` VALUES(13, '', '', '', '', '', '', '', '', 'handicap', 'handicap', 'handicap', '');
  62. INSERT INTO `amenities` VALUES(14, 'child', '', 'child', 'child', '', '', '', 'child', 'child', 'child', 'child', 'child');
  63. INSERT INTO `amenities` VALUES(15, 'pickup', '', 'pickup', '', '', 'pickup', '', '', 'pickup', 'pickup', 'pickup', '');
  64. INSERT INTO `amenities` VALUES(16, 'pet', '', 'pet', '', '', '', '', '', '', 'pet', 'pet', '');
Mar 15 '11 #7
Dormilich
8,658 Expert Mod 8TB
you should use neither of these dumps (as they are now). it may be a typo, but you create `amenities` and insert into `amenity_test` (and vice versa) … and in your PHP file, you query `inns`
Mar 16 '11 #8
dgreenhouse
250 Expert 100+
NOTE: Fixed... I think

This might be a start assuming you setup the amenities table as follows:

bnb_id int - the B&B id (foreign key to bnb table's id field)
amenity varchar(length?) - the amenity name

Here's the amenities table populated with some records:
Expand|Select|Wrap|Line Numbers
  1. bnb_id, amenity
  2.    1,   "bbq"
  3.    1,   "kitchenette"
  4.    1,   "child"
  5.    1,   "pickup"
  6.    1,   "pet"
  7.    1,   "tv"
  8.    2,   "child"
  9.    2,   "pet"
  10.    2,   "tv"
  11.  
  12.  
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $am_count = count($_POST['amenity']);
  4.  
  5. if (!$am_count) {
  6.  
  7.   $sql = "Select name FROM bnb";
  8.  
  9. } else {
  10.  
  11.   $in_clause = "";
  12.  
  13.   for ($i = 0; $i < $am_count; $i++ ) {
  14.     $in_clause .= '"' . $_POST['amenity'][$i] . ($i < $am_count -1 ? '",' : '"');
  15.   }
  16.  
  17.   $sql = 
  18.     sprintf(
  19.       "SELECT name "
  20.      . "FROM bnb "
  21.      .  "WHERE id IN "
  22.      .   "(SELECT bnb_id FROM amenities "
  23.      .     "WHERE amenity IN (%s) "
  24.      .   "GROUP BY bnb_id "
  25.      .   "HAVING COUNT(amenity) = %d)",
  26.      $in_clause, $am_count
  27.      );
  28. }
  29.  
  30. print $sql
  31.  
  32. /*
  33. SELECT name FROM bnb WHERE id IN 
  34.  (SELECT bnb_id FROM amenities 
  35.    WHERE amenity 
  36.     IN (
  37.        "bbq","kitchenette","child","pickup","pet"
  38.      ) 
  39.      GROUP BY bnb_id 
  40.      HAVING COUNT(amenity) = 5
  41.    )
  42.  
  43. *** Only B&B with an id of 1 will get selected based on the amenities selected ***
  44. */
  45. ?>
  46.  
Mar 16 '11 #9
Hi dgreenhouse I hope you are still out there. I have been playing with the code and it is not working I keep getting an error undefined index: amenity in/.....
I have simplified everything as much as I could
INN TABLE

Expand|Select|Wrap|Line Numbers
  1. -- Database: `bnbtest`
  2. --
  3. -- -----------------------------------------------------
  4. --
  5. -- Table structure for table `bnb`
  6. --
  7.  
  8. CREATE TABLE `bnb` (
  9.   `bnb_id` int(11) unsigned NOT NULL,
  10.   `image1` varchar(50) NOT NULL,
  11.   `bbName` varchar(50) NOT NULL,
  12.   `phone` varchar(20) NOT NULL,
  13.   `tollFree` varchar(20) NOT NULL,
  14.   `fax` varchar(20) NOT NULL,
  15.   `web` varchar(50) NOT NULL,
  16.   `url` varchar(50) NOT NULL,
  17.   `email` varchar(50) NOT NULL,
  18.   `emailL` varchar(50) NOT NULL,
  19.   `map` varchar(50) NOT NULL,
  20.   `image2` varchar(50) NOT NULL,
  21.   `logo1` varchar(50) NOT NULL,
  22.   `logo2` varchar(50) NOT NULL,
  23.   `logo3` varchar(50) NOT NULL,
  24.   `logo4` varchar(50) NOT NULL,
  25.   `description` varchar(4096) NOT NULL,
  26.   PRIMARY KEY (`bnb_id`)
  27. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  28. --
  29. -- Dumping data for table `bnb`
  30. --
  31. INSERT INTO `bnb` VALUES(1, '../image/inn/argyle.jpg', 'ARGYLE HOUSE', '360-378-4084', '800-624-3459', '', 'www.argylehouse.net', 'http://www.argylehouse.net', 'info@argylehouse.net', 'info@argylehouse.net', '../maps/Argyle.html', '../image/inn/argyle1.jpg', '../image/logo/threedoor.gif', '', '', '', 'Enjoy the charm and character of this 1910-vintage Craftsman located only two blocks from downtown and a short walk from the ferry.');
  32. INSERT INTO `bnb` VALUES(2, '../image/dragonfly.jpg', 'DRAGONFLY INN', '360-378-4280', '877-378-4280', '360-378-1392', 'www.thedragonflyinn.com', 'http://www.thedragonflyinn.com', 'host@thedragonflyinn.com', 'host@thedragonflyinn.com', '../maps/dragonfly.html', '../image/dragonfly1.jpg', '../image/logo/aaa3D.gif', '../image/logo/threedoor.gif', '', '', 'A unique,Japanese-inspired bed and breakfast.');
  33. INSERT INTO `bnb` VALUES(3, '../image/inn/hillside.jpg', 'HILLSIDE HOUSE', '360-378-4730', '800-232-4730', '360-378-4715 FAX', 'www.hillsidehouse.com', 'www.hillsidehouse.com', 'info@argylehouse.net', 'info@argylehouse.net', '../map/hillside.html', '../image/inn/hillside.jpg', '../image/logo/tripleA', '../image/logo/mobile', '../image/logo/3doors', '../image/logo/bellhop', 'Enjoy views of snowcapped Mt. Baker');
TABLE AMENITYTEST

Expand|Select|Wrap|Line Numbers
  1. -- Database: `bnbtest`
  2. --
  3. -- ----------------------------------------------------
  4. --
  5. -- Table structure for table `amenitytest`
  6. --
  7.  
  8. CREATE TABLE `amenitytest` (
  9.   `bnb_id` int(11) unsigned NOT NULL,
  10.   `amenity` varchar(20) NOT NULL
  11. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  12.  
  13. --
  14. -- Dumping data for table `amenitytest`
  15. --
  16.  
  17. INSERT INTO `amenitytest` VALUES(3, 'internet');
  18. INSERT INTO `amenitytest` VALUES(2, 'fireplace');
  19. INSERT INTO `amenitytest` VALUES(1, 'kitchenette');
  20. INSERT INTO `amenitytest` VALUES(2, 'bbq');
  21. INSERT INTO `amenitytest` VALUES(3, 'breakfast');
and here is the process page

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>checkboxes</title>
  4. </head>
  5.  
  6. <body>
  7. <?php 
  8. //connect
  9. mysql_connect("localhost", "root", "root") or die(mysql_error());
  10. mysql_select_db("bnbtest") or die(mysql_error());
  11.  
  12. //selects all columns from bnb
  13. $query = 'SELECT * FROM bnb';
  14.  
  15. //retrieves the records
  16. $result = mysql_query($query);
  17. if (!$result) {
  18.     die('Query failed: ' . mysql_error());
  19. }
  20.  
  21.         $am_count = count($_POST['amenity']);
  22.  
  23.         if (!$am_count) {
  24.  
  25.             $sql = "SELECT * FROM bnb";
  26.  
  27.         } else {
  28.             $in_clause = "";
  29.  
  30.             for ($i = 0; $i < $am_count; $i++) {
  31.  
  32.                 $in_clause .= ' " ' . $_POST['amenity'][$i] . ($i < $am_count -1 ? '",' : '"');
  33.             }
  34.  
  35.             $sql=
  36.             sprintf(
  37.             "SELECT *"
  38.             . "FROM bnb"
  39.             .  "WHERE id IN"
  40.             .   "(SELECT bnb_id FROM amenitytest"
  41.             .     "WHERE amenity IN (%s)"
  42.             .    "GROUP by bnb_id"
  43.             .    "HAVING COUNT (amenity) = %d)",
  44.             $in_clause, $am_count);
  45.  
  46.  
  47. // Print out the contents of the entry 
  48. echo $row['bbName'] . "<br />";
  49. echo $row['url'] . "<br />";
  50. echo $row['phone'] . "<br />";
  51. echo $row['tollFree'] . "<br />";
  52. echo $row['fax'];
  53. echo $row['web'] . "<br />";
  54. echo $row['email'] . "<br />";
  55. echo $row['description'] . "<br />". "<br />";
  56. }
  57. mysql_close()
  58. ?>
  59. </body>
  60. </html>
Mar 24 '11 #10
Dormilich
8,658 Expert Mod 8TB
you never check, whether $_POST['amenity'] actually exists (isset()).
Mar 24 '11 #11
I placed
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['amenity']))
  2. //connect
  3. mysql_connect("localhost", "root", "root") or die(mysql_error());
  4. mysql_select_db("bnbtest") or die(mysql_error());
and my error now is Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user........

I know that the connection is correct because it works for all my other simple test. for instance I just finished creating this example below and all the inns that have breakfast (WHERE amenity.breakfast ='y') come up. the table is an older one I used before with y and n.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Make a MySQL Connection
  4. mysql_connect("localhost", "root", "root") or die(mysql_error());
  5. mysql_select_db("bnbtest") or die(mysql_error());
  6.  
  7.  
  8. // Retrieve all the data from the "example" table
  9.  
  10. $result = mysql_query("SELECT bnb.* 
  11.                         FROM amenity, bnb 
  12.                         WHERE amenity.breakfast = 'y' 
  13.                         AND amenity.bnb_id = bnb.bnb_id
  14.                         LIMIT 0,30")
  15. or die(mysql_error()); 
  16.  
  17.  
  18. //store the record of the bnb and amenity table into $row
  19. while($row = mysql_fetch_array($result)) {
  20.  
  21. // Print out the contents of the entry 
  22. echo $row['bbName'] . "<br />";
  23. echo $row['url'] . "<br />";
  24. echo $row['phone'] . "<br />";
  25. echo $row['tollFree'] . "<br />";
  26. echo $row['fax']. "<br />";
  27. echo $row['web'] . "<br />";
  28. echo $row['email'] . "<br />";
  29. echo $row['description'] . "<br />". "<br />";
  30. }
  31. ?>
Mar 24 '11 #12
Dormilich
8,658 Expert Mod 8TB
you are aware that an if() condition without {} only works on the next line (the mysql_connect())? thus when calling mysql_select_db() I think PHP tries to use the defaults from php.ini, which may cause that error.

one more reason to use MySQLi (or even better: PDO) instead of the outdated mysql functions.
Mar 24 '11 #13
thanks I did not understand the brackets,
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['amenity']))
  2. {
  3. //connect..............
  4. //all the same code
  5.  
  6. echo $row['description'] . "<br />". "<br />";
  7. }
  8. }//thanks for the bracket info
  9.  
  10. mysql_close()//now it says this is a problem
I am getting

Warning: mysql_close(): no MySQL-link resource supplied in........
Mar 26 '11 #14
Also I started to read about MySQLi and PDO. I am not sure but MySQLi seems simpler because it works with MySQL.
With PDO there is a warning that some MySQL table do not support transactions.
I am new at programing and I would like to go in the right direction
thanks for all your help
Mar 26 '11 #15
Dormilich
8,658 Expert Mod 8TB
you cannot close a connection you don’t have (i.e. include the close in the brackets)
Mar 26 '11 #16
Well it's done I would like to thank Dormilich and dgreenhouse for all your help. I want to post this for anyone else who has the same problems I had with checkboxes. I left the checkboxes as an html file and posted to this file. You will have to create the table there is a sample above and like Dormilich says create two tables
thanks again

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['amenity']))
  3. {    
  4.     //Build a where clause based on the form
  5.     $where = false;
  6.     foreach($_POST['amenity'] as $amenity)
  7.     {
  8.         if(!$where)
  9.         {
  10.             $where = 'WHERE a.'. $amenity." = 'y'";
  11.         }
  12.         else
  13.         {
  14.             $where .= 'AND a.'. $amenity." = 'y'";
  15.         }
  16.     }
  17.     $mysqli = new mysqli('localhost', 'root', 'root', 'bnbtest');
  18.  
  19.  
  20.     $sql ="
  21.         SELECT    bnb.*
  22.         FROM    bnb
  23.         JOIN    amenity as a
  24.         ON        a.bnb_id = bnb.bnb_id
  25.         $where
  26.     ";     
  27.  
  28.     $result = $mysqli->query( $sql );
  29.     while ($row = $result->fetch_assoc()) {
  30.         echo $row['bbName'] . "<br />";
  31.         echo $row['url'] . "<br />";
  32.         echo $row['phone'] . "<br />";
  33.         echo $row['tollFree'] . "<br />";
  34.         echo $row['fax'] . "<br />";
  35.         echo $row['web'] . "<br />";
  36.         echo $row['email'] . "<br />";
  37.         echo $row['description'] . "<br />" ."<br />";
  38.     }
  39.  
  40.     $mysqli->close();
  41. }
  42. ?>
Mar 28 '11 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
2
by: ANSWER | last post by:
Hi, What is the best way to make help file for users in Access database. Thanks
1
by: handsomejay | last post by:
Good day, I am learning C# and someone has given me a certain software to write for him. I have been trying to add a new record to the Access Database that has already been added to the a Visual C#...
0
by: wertqt | last post by:
hi all, im facing this problem and do not know where to start from. Lets say i have this column called 'In-Charge". In-Charge John John ...
0
by: dhaneshrs | last post by:
Heya guys, i need your urgent help.. Its in ASP .NET with Access DB. I am attaching the file i have done so far from various sources and help from people around me. My friends who have worked with...
3
by: rizwanrazzaq | last post by:
Hi friends here is my coding.. but i m facing one problem .. i used both mathod SQL mathod and open Record Set. but in both i m getting error massage can anyone help me out regarding thi. Please...
0
by: NaziaAkter | last post by:
Hi, I have a website. where user are selecting some items and storing in the database. Whwn a user click view it shows all the selected item from the database. Now what I want in view every item...
14
by: gilsygirl | last post by:
Hello everyone Am using a For Loop to access records from my database but the code opens instead of a specific record base on values passed by the user. These values a fields in the database...
4
by: Hepburn08 | last post by:
Hi, I need some help opening a corrupt Microsoft Access database file. I get an error message that says "unrecognized database format". Since I can't open it, I can't export the data to another new...
1
by: asp beginner | last post by:
I am building an Eccomerce site and I am trying to make my shopping cart work. I am having a problem with when I have entered data into my form it is not submitting into my access database. This my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.