elim Posted March 20, 2013 Share Posted March 20, 2013 (edited) 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 March 20, 2013 by elim Quote Link to comment https://forums.phpfreaks.com/topic/275939-creating-search-box-help-using-mysql/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.