Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Location
    Tennessee
    Posts
    6

    Question Unanswered: 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 21:24.

  2. #2
    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.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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 on the Tiger 800 or the Norton

  4. #4
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •