Jump to content

Recommended Posts

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 perfectly however I want to add a search box that will search upon the first name attribute.

 

any help?

<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
            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>
 
Edited by elim
Link to comment
https://forums.phpfreaks.com/topic/275939-creating-search-box-help-using-mysql/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.