creating search box to filter data
Results 1 to 4 of 4

Thread: creating search box to filter data

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1

    creating search box to filter data

    first of all I'm using this site as a template for what I'm trying to do except im adding a search box on top www.dougv.com/demo/jquery_sort_records/js.php (for some reason link doesnt work so copy and paste into browser)

    I want to create a simple search box that will search upon a certain attribute and display any results found (basically a filter). Here's what I have so far as part of the code.
    so far the table appears well however I want to add a search box that will search upon the first name attribute.

    any help?
    Code:
    <script type="text/javascript" src="jquery-1.3.1.min.js"></script>
    <script type="text/javascript" src="jquery.tablesorter.min.js"></script>
    <script type="text/javascript">
                $(document).ready(function() {
                    $("#sortedtable").tablesorter({ sortlist: [0,0] });
                });
            </script>
    
    </head>
    <body>
    
    PHP Code:
    <?php             if(!$link mysql_connect("database_server""user_name""password")) {                 echo "Cannot connect to db server";             }             elseif(!mysql_select_db("database_name")) {                 echo "Cannot select database";             }             else {                 if(!$rs mysql_query("SELECT * FROM table")) {                     echo "Cannot parse query";                 }                 elseif(mysql_num_rows($rs) == 0) {                     echo "No records found";                 }                 else {                     echo "<table id=\"sortedtable\" class=\"bordered\" cellspacing=\"0\">\n";                     echo "<thead>\n<tr>";                     echo "<th>Record ID</th>";                     echo "<th>First Name</th>";                     echo "<th>Last Name</th>";                     echo "<th>Birthday</th>";                     echo "<th>Department</th>";                     echo "</tr>\n</thead>\n";                     while($row mysql_fetch_array($rs)) {                         echo "<tr><td>$row[person_id]</td><td>$row[person_name]</td><td>$row[person_surname]</td><td>$row[person_birthdate]</td><td>$row[person_department]</td></tr>\n";                     }                     echo "</table><br />\n";                 }             } ?>
    <form name="search_form" method="POST" action="js.php"> <font face="Calibri"> </font> Search: <input type="text" name="search_b" value="" /> <input type="submit" name="search" value="Search for your term..."> </input> </form>

  2. #2
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,697
    Well, do you know how to search a database?

    Code:
    SELECT FIRSTNAME,LASTNAME,USERID FROM USERTABLE WHERE NAME LIKE "%FRED%";
    
    SELECT FIRSTNAME,LASTNAME,USERID FROM USERTABLE WHERE NAME REGEXP "FLINTSTONE";
    And so on ... several times until you think you've got most of the possibilities covered.
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  3. #3
    Senior Member Roger Ramjet's Avatar
    Join Date
    Jul 2004
    Location
    Leeds, UK
    Posts
    4,203
    Since you are happy using jquery why not use the datatables plugin http://www.datatables.net/
    It is really slick, really easy to use and has all the sort and filter functions that you need built it.

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    18
    Thanks "roger" for sharing plugin link. It will be a great help for me in my programming work.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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