If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Combo Box to Filter a Table Please HELP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-23-11, 20:17
BoroBid BoroBid is offline
Registered User
 
Join Date: Aug 2011
Location: Tennessee
Posts: 6
Question Combo Box to Filter a Table Please HELP

Hey guys I am having some issues... I am new to coding so most of the stuff I have is from other forums and friends helping me out but I am stuck.

I have a table pulling from a mySQL database database name is daobrien21 the tables name is Test below is the code for the data base and table and drop down


Code:
<?php
$connect = mysql_connect("hosted.domain.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><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>";
?>
What I am looking for is when I select a bar name in the drop down it filters the table to only display that bar in it. Can you guys help me out please.

Last edited by BoroBid; 08-23-11 at 20:24.
Reply With Quote
  #2 (permalink)  
Old 08-23-11, 20:34
BoroBid BoroBid is offline
Registered User
 
Join Date: Aug 2011
Location: Tennessee
Posts: 6
Also I have already searched this form but did not find very many articles that have helped out.
Reply With Quote
  #3 (permalink)  
Old 08-24-11, 04:18
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
the web design paradigm is different to what used to be regarded as a normal program.
you either have to SUBMIT the form with values and wait for a response from the server
OR
with the advent of "Web 2" you could get close to faking a traditional program by using AJAX or similar. the web page has some javascript on it that sends a request to the server, the page remains active and responds to the information retrieved from the server.

my guess is that where you are at now a traditional web page using a FORM element SUBMITting data to the server is probably the right way to go.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 08-24-11, 09:08
BoroBid BoroBid is offline
Registered User
 
Join Date: Aug 2011
Location: Tennessee
Posts: 6
I think that is where I want to be... Sorry I am new to this coding world. I learned basic web page design in FrontPage and that’s it so I am learning... it’s starting to clear up some... I am at the stage when your learning a new language and you got the nouns figured out but can’t put them in the right place in a sentence haha

So what I am asking is to dumb it down some for me if you can sorry to be a newbie.
Reply With Quote
Reply

Tags
combo box, filter, php, table

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On