Web Analytics Made Easy -
StatCounter Filter results in table HELP - CodingForum

Announcement

Collapse
No announcement yet.

Filter results in table HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filter results in table HELP

    OK I am wanting to build a table that I can enter data in to and have people sort by a drop down box like the 4th table down on this list -- http://www.javascriptkit.com/script/...lefilter.shtml

    But I have followed those instructions step by step and it never works. I was told to use .asp I have changed my page to a .asp and now have no clue where to go from here. In searching this site I have found this code --

    [CODE]
    <script>
    function Filter(table){
    var f=document.getElementById('f').value.toUpperCase();
    for (a=1; a<table.rows.length; a++)
    {
    if (table.rows[a].cells[0].innerHTML.toUpperCase().indexOf(f)!=0)
    table.rows[a].style.display="none"; else
    table.rows[a].style.display="table-row";
    }
    }
    </script>

    <table id="states" border=1>
    <tr><td>State</td><td>Code</td></tr>
    <tr><td>ALABAMA</td><td>AL</td></tr>
    <tr><td>ALASKA</td><td>AK</td></tr>
    <tr><td>MAINE</td><td>ME</td></tr>
    <tr><td>MARSHALL ISLANDS</td><td>MH</td></tr>
    </table>

    <form>
    <input type="text" name="f" id="f">
    <input type="button" value="Filter" onclick="Filter(document.getElementById('states'));">
    </form>
    [CODE]

    But it gives me a filter that I have to type in. I am looking for drop downs that allow me to filter so say you select drop down for fields that contain "A" then another drop down for a field that contains "B" so the results show fields that contain "A" and "B"

    And PS I am semi new to the code world so please don't assume I know some stuff dumb it down a little HAHA

  • #2
    No one knows how to do this?

    Comment


    • #3
      Ok I have figured out a drop down box with the bar's name in it but now I cant figure out how to make it edit my table so when I select the bars name it just displays that bars information? Any one have any ideas please??

      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>";
      ?>

      Comment

      Working...
      X