Jump to content

creating search box help using mysql


elim

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.