...

View Full Version : HELP PHP MYSQL combobox filtering



red71chevelle
08-24-2011, 09:00 PM
Ok guys I have a question. I am working on getting a table that has bar names and information from my data base in it and I want a drop down to filter the table so if someone selects a name from the drop down it just shows that bars name and information that they slected. Easy concept in my mind but has proven to be difficult.

I was told by someone here in the Java forum that I needed to get my code right first and they suggested I ask the question in the PHP forum so here I am. He said

1. You should have shorter values for the options. Just short identifiers
2. You should give each <tr> an id attribute which corresponds to the values of the options. This will enable you to easily hide lines based upond the selected value

you can see the convo here -- http://www.codingforums.com/showthread.php?t=235936


Below is the code for my page if you view/pagesource


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<!-- #BeginTemplate "master.dwt" -->

<head>
<!-- #BeginEditable "doctitle" -->
<title>Murfreesboro Bars</title>
<style type="text/css">
.style4 {
text-align: center;
font-family: "BankGothic Md BT";
}
.style5 {
text-align: center;
font-family: "BankGothic Md BT";
font-size: medium;
}
</style>
<!-- #EndEditable -->
<link rel="stylesheet" type="text/css" href="styles/style3.css">
<style type="text/css">
.style1 {
margin-bottom: 3px;
}
.style2 {
margin-left: 0px;
}
</style>
</head>

<body style="background-image: url('images/wallpaper-cf2-1440x900.jpg');">

<!-- Begin Container -->
<div id="container" class="style2">
<!-- Begin Masthead -->
<div id="masthead">
<h1 class="style1" style="width: 576px; height: 69px">
<img alt="TNBarFinder Logo" height="70" longdesc="TNBarFinder Logo" src="images/tnbarfinderlogo.jpg" width="580" /></h1>
</div>
<!-- End Masthead -->
<!-- Begin Navigation -->
<div id="navigation">
<ul>
<li><a href="default.htm">Home</a></li>
<li><a href="about_me/about_me.htm">About Us </a></li>
<li><a href="photo_gallery/photo_gallery.htm">Photo Gallery</a></li>
<li><a href="links/links.htm">Extra Page</a></li>
<li><a href="contact/contact.htm">Contact</a></li>
</ul>
</div>
<!-- End Navigation -->
<!-- Begin content_container -->
<div id="content_container">
<!-- Begin Left Column -->
<div id="column_left" style="width: 595px">
<!-- #BeginEditable "content" -->
<p>&nbsp;</p>
<h2 class="style4">Murfreesboro's bars and specials</h2>
<p class="style5"><strong>Sort by what your looking for</strong></p>
<p>&nbsp;</p>


<select name='Bar'>
<option value='Liquid Smoke'>Liquid Smoke</option>
<option value='The Boro Bar & Grill'>The Boro Bar & Grill</option>
<option value='Bluesboro'>Bluesboro</option>
<option value='Wagon Wheel Lounge'>Wagon Wheel Lounge</option>
<option value='Mellow Mushroom'>Mellow Mushroom</option>
<option value='Gentleman Jim's Bar & Grill'>Gentleman Jim's Bar & Grill</option>
<option value='Toot's'>Toot's</option>
<option value='Fanatics'>Fanatics</option>
<option value='Buster's Place'>Buster's Place</option>
<option value='Chili's Grill & Bar'>Chili's Grill & Bar</option>
<option value='Temptation Club'>Temptation Club</option>
<option value='Aura Lounge'>Aura Lounge</option>
<option value='Hooters'>Hooters</option>
<option value='Buffalo Wild Wings '>Buffalo Wild Wings </option>
<option value='Fat Willies Billiards'>Fat Willies Billiards</option>
<option value='Dugger's Food & Fun'>Dugger's Food & Fun</option>
<option value='Five Senses Restaurant & Bar'>Five Senses Restaurant & Bar</option>
<option value='Mark & Wolf's Handlebar'>Mark & Wolf's Handlebar</option>
<option value='Bullseye Sportsbar Inc'>Bullseye Sportsbar Inc</option>
<option value='Gentleman Jim's Bar & Grill'>Gentleman Jim's Bar & Grill</option>
<option value='Campus Pub'>Campus Pub</option>
<option value='Revolver Saloon'>Revolver Saloon</option>
<option value='On The Rocks'>On The Rocks</option>
<option value='Applebees'>Applebees</option>
<option value='Nobody's Sports Grille & BBQ'>Nobody's Sports Grille & BBQ</option>
<option value='JD's Music'>JD's Music</option>
<option value='El Tequila Inc'>El Tequila Inc</option>
<option value='Toasted Toad'>Toasted Toad</option>
<option value='Genghis Grill'>Genghis Grill</option>
<option value='2 Sound Productions'>2 Sound Productions</option>
<option value='Blue Rooster'>Blue Rooster</option>
<option value='Bobby McKee's Irish Pub'>Bobby McKee's Irish Pub</option>
<option value='Spot Bar & Grill'>Spot Bar & Grill</option>
<option value='D&D Lounge'>D&D Lounge</option>
<option value='Music Madness'>Music Madness</option>
<option value='Pawbowskys' Dog House'>Pawbowskys' Dog House</option>
<option value='Willie's Wet Spot'>Willie's Wet Spot</option>
<option value='Coconut Bay Caf'>Coconut Bay Caf</option>
<option value='Mi Terra Mexican Restaurant'>Mi Terra Mexican Restaurant</option>
<option value='Wall Street'>Wall Street</option>
<option value='Darlin's Bar & Grill'>Darlin's Bar & Grill</option>
<option value='Sullivan's Sports Bar'>Sullivan's Sports Bar</option>
<option value='Ron's Tavern'>Ron's Tavern</option>
<option value='Clarion Inn & Suites'>Clarion Inn & Suites</option>
<option value='Pop's Bar & Grill'>Pop's Bar & Grill</option>
<option value='Charlie's Dart Country'>Charlie's Dart Country</option>
<option value='Coach's Grill'>Coach's Grill</option>
<option value='The Parthenon Restaurant'>The Parthenon Restaurant</option>
<option value='Buffalo Wild Wings '>Buffalo Wild Wings </option>
<option value='Restaurant & Lounge Mt Bottle'>Restaurant & Lounge Mt Bottle</option>
<option value='Townleys'>Townleys</option>
<option value='T.G.I. Friday's'>T.G.I. Friday's</option>
<option value='Raz'z Bar & Grill'>Raz'z Bar & Grill</option>
<option value='Shoeless Joes'>Shoeless Joes</option>
<option value='Mark & Pats Handlebar'>Mark & Pats Handlebar</option>
<option value='Graffiti Bar'>Graffiti Bar</option>
<option value='Chappy's Bar & Grill'>Chappy's Bar & Grill</option>
<option value='Murfreesboro Lions Club'>Murfreesboro Lions Club</option>
<option value='P J's Pub'>P J's Pub</option>
</select><table border=1 style="background-color:#F0F8FF;" >
<caption><EM>Murfreesboro Bars</EM></caption>
<tr>
<th>Bar Name</th>
<th>City</th>
<th>Address</th>
<th>Phone</th>
</tr>
<td>Liquid Smoke</td><td>Murfreesboro</td><td> 2 Public Square</td><td>615-217-7822</td></tr><td>The Boro Bar & Grill</td><td>Murfreesboro</td><td>1211 Greenland Drive</td><td>615-895-4800</td></tr><td>Bluesboro</td><td>Murfreesboro</td><td>114 North Church Street</td><td>615-904-7236</td></tr><td>Wagon Wheel Lounge</td><td>Murfreesboro</td><td>534 Southeast Broad Street </td><td>615-896-9009</td></tr><td>Mellow Mushroom</td><td>Murfreesboro</td><td>2955 South Rutherford Boulevard</td><td>615-890-8898</td></tr><td>Gentleman Jim's Bar & Grill</td><td>Murfreesboro</td><td>1325 Greenland Drive</td><td>615-893-9933</td></tr><td>Toot's</td><td>Murfreesboro</td><td>860 Northwest Broad Street</td><td>615-898-1301</td></tr><td>Fanatics</td><td>Murfreesboro</td><td>1850 Old Fort Parkway</td><td>615-494-3995</td></tr><td>Buster's Place</td><td>Murfreesboro</td><td>1615 Northwest Broad Street</td><td>615-895-5464</td></tr><td>Chili's Grill & Bar</td><td>Murfreesboro</td><td>755 Northwest Broad Street</td><td>615-867-2855</td></tr><td>Temptation Club</td><td>Murfreesboro</td><td>2404 Halls Hill Pike</td><td>615-217-0944</td></tr><td>Aura Lounge</td><td>Murfreesboro</td><td>114 South Maple Street</td><td>615-396-8328</td></tr><td>Hooters</td><td>Murfreesboro</td><td>1310 NW Broad Street</td><td>615-867-2337</td></tr><td>Buffalo Wild Wings </td><td>Murfreesboro</td><td>207 Stones River Mall Blvd</td><td>615-907-6004</td></tr><td>Fat Willies Billiards</td><td>Murfreesboro</td><td>244 River Rock Boulevard</td><td>615-848-1801</td></tr><td>Dugger's Food & Fun</td><td>Murfreesboro</td><td>1738 West Northfield Boulevard</td><td>615-809-2605</td></tr><td>Five Senses Restaurant & Bar</td><td>Murfreesboro</td><td>1602 West Northfield Boulevard</td><td>615-867-4155</td></tr><td>Mark & Wolf's Handlebar</td><td>Murfreesboro</td><td>2601 E Main St</td><td>615-890-5661</td></tr><td>Bullseye Sportsbar Inc</td><td>Murfreesboro</td><td>225 River Rock Boulevard</td><td>615-896-6994</td></tr><td>Gentleman Jim's Bar & Grill</td><td>Murfreesboro</td><td>2115 East Main Street</td><td>615-896-9716</td></tr><td>Campus Pub</td><td>Murfreesboro</td><td>903 Gunnerson Avenue</td><td>615-867-9893</td></tr><td>Revolver Saloon</td><td>Murfreesboro</td><td>2227 Old Fort Parkway</td><td>615-530-4008</td></tr><td>On The Rocks</td><td>Murfreesboro</td><td>211 W. Main Street</td><td>615-375-6055</td></tr><td>Applebees</td><td>Murfreesboro</td><td>2896 South Rutherford Boulevard</td><td>615-895-7777</td></tr><td>Nobody's Sports Grille & BBQ</td><td>Murfreesboro</td><td>116 John R Rice Boulevard</td><td>615-962-8019</td></tr><td>JD's Music</td><td>Murfreesboro</td><td>109 Marauder Court</td><td>615-849-3533</td></tr><td>El Tequila Inc</td><td>Murfreesboro</td><td>2349 South Church Street</td><td>615-898-0333</td></tr><td>Toasted Toad</td><td>Murfreesboro</td><td>2227 Old Fort Parkway</td><td>615-504-6004</td></tr><td>Genghis Grill</td><td>Murfreesboro</td><td>2615 Medical Center Pkwy Ste. 2250</td><td>615-494-1181</td></tr><td>2 Sound Productions</td><td>Murfreesboro</td><td>Tennessee 96</td><td>615-867-4596</td></tr><td>Blue Rooster</td><td>Murfreesboro</td><td>114 North Church Street</td><td>615-904-7236</td></tr><td>Bobby McKee's Irish Pub</td><td>Murfreesboro</td><td>1720 Old Fort Parkway #100</td><td>615-439-6021</td></tr><td>Spot Bar & Grill</td><td>Murfreesboro</td><td>4425 Woodbury Pike</td><td>615-396-8574</td></tr><td>D&D Lounge</td><td>Murfreesboro</td><td>6022 New Nashville Highway</td><td>615-896-6556</td></tr><td>Music Madness</td><td>Murfreesboro</td><td></td><td>614-631-3914</td></tr><td>Pawbowskys' Dog House</td><td>Murfreesboro</td><td>3080 South Church Street</td><td>615-849-1734</td></tr><td>Coconut Bay Caf</td><td>Murfreesboro</td><td>210 Stones River Mall Boulevard</td><td>615-494-0504</td></tr><td>Wall Street</td><td>Murfreesboro</td><td>121 North Maple Street</td><td>615-867-9090</td></tr><td>Clarion Inn & Suites</td><td>Murfreesboro</td><td>2227 Old-Fort Parkway</td><td>615-896-2420</td></tr><td>Coach's Grill</td><td>Murfreesboro</td><td>127 Southeast Broad Street</td><td>615-962-7853</td></tr><td>The Parthenon Restaurant</td><td>Murfreesboro</td><td>1935 South Church Street</td><td>615-895-2665</td></tr><td>Restaurant & Lounge Mt Bottle</td><td>Murfreesboro</td><td>3940 Shelbyville Hwy</td><td>615-962-9872</td></tr><td>T.G.I. Friday's</td><td>Murfreesboro</td><td>1714 Old Fort Pkwy</td><td>615-907-3086</td></tr><td>Shoeless Joes</td><td>Murfreesboro</td><td>1850 Old Fort Parkway</td><td>615-494-1873</td></tr><td>Mark & Pats Handlebar</td><td>Murfreesboro</td><td>2601 E Main St</td><td>615-890-5661</td></tr><td>Graffiti Bar</td><td>Murfreesboro</td><td>2962 S Rutherford Blvd.</td><td>615-439-6041</td></tr><td>Murfreesboro Lions Club</td><td>Murfreesboro</td><td>Cannonsburg</td><td>615-893-2582</td></tr></table>


<p>&nbsp;</p>
<p>&nbsp;</p>
<!-- #EndEditable --></div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<!-- End Right Column -->
<!-- Begin Footer -->
<div id="footer">
<div id="copyright">
<p>Copyright
<a href="http://www.tnbarfinder.com/">TNBarFinder</a> �2011.
.</p>
</div>
<p><a href="default.htm">Home</a> | <a href="about_me/about_me.htm">About
Me</a> |
<a href="photo_gallery/photo_gallery.htm">Photo Gallery</a> |
<a href="links/links.htm">Links</a> | <a href="contact/contact.htm">
Contact</a></p>
</div>
<!-- End Footer --></div>
<!-- End content_container --></div>
<!-- End Container -->

</body>

<!-- #EndTemplate -->

</html>


This is the code when I open the page to edit it


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">

<!-- #BeginTemplate "master.dwt" -->

<head>
<!-- #BeginEditable "doctitle" -->
<title>Murfreesboro Bars</title>
<style type="text/css">
.style4 {
text-align: center;
font-family: "BankGothic Md BT";
}
.style5 {
text-align: center;
font-family: "BankGothic Md BT";
font-size: medium;
}
</style>
<!-- #EndEditable -->
<link rel="stylesheet" type="text/css" href="styles/style3.css">
<style type="text/css">
.style1 {
margin-bottom: 3px;
}
.style2 {
margin-left: 0px;
}
</style>
</head>

<body style="background-image: url('images/wallpaper-cf2-1440x900.jpg');">

<!-- Begin Container -->
<div id="container" class="style2">
<!-- Begin Masthead -->
<div id="masthead">
<h1 class="style1" style="width: 576px; height: 69px">
<img alt="TNBarFinder Logo" height="70" longdesc="TNBarFinder Logo" src="images/tnbarfinderlogo.jpg" width="580" /></h1>
</div>
<!-- End Masthead -->
<!-- Begin Navigation -->
<div id="navigation">
<ul>
<li><a href="default.htm">Home</a></li>
<li><a href="about_me/about_me.htm">About Us </a></li>
<li><a href="photo_gallery/photo_gallery.htm">Photo Gallery</a></li>
<li><a href="links/links.htm">Extra Page</a></li>
<li><a href="contact/contact.htm">Contact</a></li>
</ul>
</div>
<!-- End Navigation -->
<!-- Begin content_container -->
<div id="content_container">
<!-- Begin Left Column -->
<div id="column_left" style="width: 595px">
<!-- #BeginEditable "content" -->
<p>&nbsp;</p>
<h2 class="style4">Murfreesboro's bars and specials</h2>
<p class="style5"><strong>Sort by what your looking for</strong></p>
<p>&nbsp;</p>


<?php
$connect = mysql_connect("hosted.resource.com", "username", "password") or
die ("Hey loser, check your server connection.");
mysql_select_db("daobrien21");
?>
<?php
// Write out our query to get the list of bar names from our DB.
$query = "SELECT Bar FROM Test";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());


$dropdown = "<select name='Bar'>";

//fetch_assoc will get the rows from the $result and put them into an array
// the while loop then loops through the array wrapping the html code around the results
// thus generating the dropdown with a list of your bar names
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['Bar']}'>{$row['Bar']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
?>
<?php
$query="select * from Test";
$result = mysql_query("SELECT * FROM Test where City='Murfreesboro'");
?>
<table border=1 style="background-color:#F0F8FF;" >
<caption><EM>Murfreesboro Bars</EM></caption>
<tr>
<th>Bar Name</th>
<th>City</th>
<th>Address</th>
<th>Phone</th>
</tr>
<?php
while($row=mysql_fetch_array($result)){
echo "<td>";
echo $row['Bar'];
echo "</td><td>";
echo $row['City'];
echo "</td><td>";
echo $row['Address'];
echo "</td><td>";
echo $row['Phone'];
echo "</td></tr>";
}
echo "</table>";
?>



<p>&nbsp;</p>
<p>&nbsp;</p>
<!-- #EndEditable --></div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<!-- End Right Column -->
<!-- Begin Footer -->
<div id="footer">
<div id="copyright">
<p>Copyright
<a href="http://www.tnbarfinder.com/">TNBarFinder</a> �2011.
.</p>
</div>
<p><a href="default.htm">Home</a> | <a href="about_me/about_me.htm">About
Me</a> |
<a href="photo_gallery/photo_gallery.htm">Photo Gallery</a> |
<a href="links/links.htm">Links</a> | <a href="contact/contact.htm">
Contact</a></p>
</div>
<!-- End Footer --></div>
<!-- End content_container --></div>
<!-- End Container -->

</body>

<!-- #EndTemplate -->

</html>

Can anyone here help me get the drop down to filter the table below it?

red71chevelle
08-25-2011, 02:45 PM
Too much reading? Or no one knows?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum