PHP and HTML table search using javascript -


i want create search box, displays matched entries search phrases typed; same in function described here:

how perform real time search , filter on html table

the difference is, table have created php loop - , sql data. but, unsure how adopt code work me.

personally, think related "// printing table rows" section.

here code:

var $search_rows = $('#table tr');  $('#search').keyup(function() {      var val = $.trim($(this).val()).replace(/ +/g, ' ').tolowercase();        $search_rows.show().filter(function() {          var text = $(this).text().replace(/\s+/g, ' ').tolowercase();          return !~text.indexof(val);      }).hide();  });
<html>    <script src="./jquery-1.6.4.js"></script>  <script src="./sorttable.js"></script>  <script src="./searchbox.js"></script>    <link rel="stylesheet" href="styles.css">    <head>  <title>tau empire cadre census</title>  </head>    <body>  <?php      //// //// //// ////  // database  //// //// //// ////    //database credentials  $db_host="localhost";  $db_user="tau";  $db_pwd="kuhohng3";  $db="tau_census";  $db_table="cadres";    //make connection  if (!mysql_connect($db_host, $db_user, $db_pwd))      die("can't connect database");    if (!mysql_select_db($db))      die("can't select database");    // sending query  $result = mysql_query("select * {$db_table}");  if (!$result) {      die("query show fields table failed");  }    //assign variable number of returned table fields  $fields_num = mysql_num_fields($result);      //// //// //// ////  // heading  //// //// //// ////    echo "<h1>tau empire cadre census</h1>";  // search box  echo '<input type="text" id="search" placeholder="type search">';      //// //// //// ////  // table  //// //// //// ////    //create table, , use js sortable script  echo '<table id="table" class="sortable"><tr>';    // printing table headers  echo "<td class=headings>designation</td>";  echo "<td class=headings>location</td>";  echo "<td class=headings>founding</td>";  echo "<td class=headings>commanding officer</td>";  echo "<td class=headings>current status</td>";  echo "<td class=headings>current location</td>";  echo "<td class=headings>mission</td>";    echo "</tr>\n";    // printing table rows  while($row = mysql_fetch_row($result))  {      echo "<tr>";      // each field print content      for($i=1; $i<$fields_num; $i++) {          echo "<td>" . $row[$i] . "</td>";      }      echo "</tr>";  }    echo "</table>";    mysql_free_result($result);    ?>    </body>  </html>

running not throw errors, nor work either. requires brains greater mine work out, please.

i have working now, assistance. possible combination of following:

i) having following script lines inserted correctly:

<script src="./jquery.min.js"></script> <script src="./jquery-1.6.4.js"></script> 

ii) wrapping external js in $(function(){...});

iii) incorrectly constructing table rows , data fields.


Comments