Question

i am using jquery table to show table on a web page.The table is coming up properly but paging for the table and showing number of records and search options are not working for the table generated.All the records are populating at the load of the page.This is my code PHP code

$qry = " SELECT AssetId,";
$qry .= $data; 
$qry .= " from Completedetails";

mysql_select_db($database_finalkms, $finalkms);
$query_getcolumns = $qry;
$getcolumns = mysql_query($query_getcolumns, $finalkms) or die(mysql_error());
$row_getcolumns = mysql_fetch_assoc($getcolumns);
$totalRows_getcolumns = mysql_num_rows($getcolumns);

if (($getcolumns)||(mysql_errno == 0))  
{  
  echo "<table width='50%' id='sample_2'><thead><tr>";  
  if (mysql_num_rows($getcolumns)>0)  
  {  
          //loop thru the field names to print the correct headers  
          $i = 0;  
          while ($i < mysql_num_fields($getcolumns))  
          {  
       echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";  
       $i++;  
    }  
    echo "</tr></thead>";  

    //display the data  
    while ($rows = mysql_fetch_array($getcolumns,MYSQL_ASSOC))  
    {  
      echo "<tbody><tr >";  
      foreach ($rows as $data)  
      {  
        echo "<td align='center'>". $data . "</td>";  
      }  
    }  
  }else{  
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";  
  }  
  echo "</tbody></table>";  
}else{  
  echo "Error in running query :". mysql_error();  
}  

?>

Java Script

<script>
 jQuery(document).ready(function() {       
  // initiate layout and plugins
  $("#sample_2").dataTable({"bPaginate": true});
 });
</script>

<input name="hdnfld" id="hdnfld" type="hidden" value="<?php echo $qry;?>"/>

Please help me in this regard.

Was it helpful?

Solution

Try the following modified code of yours, if still not working then give the live URl where ur html output is displyed.

if (($getcolumns)||(mysql_errno == 0))  
{
  // Displying the headers
  $i = 0;
  echo "<table width='50%' id='sample_2'><thead><tr>";
  while ($i < mysql_num_fields($getcolumns))  
  {  
    echo "<th align='center'>". mysql_field_name($getcolumns, $i) . "</th>";  
    $i++;  
  }  
  echo "</tr></thead>";  

  // Data Section
  echo "<tbody>";
  if (mysql_num_rows($getcolumns)>0)  
  {
    while ($rows = mysql_fetch_array($getcolumns, MYSQL_ASSOC))  
    {  
      echo "<tr>";
      foreach ($rows as $data)  
      {  
        echo "<td align='center'>". $data . "</td>";  
      }
      echo "</tr>";
    }  
  }else{  
    echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";  
  }  
  echo "</tbody></table>";  
}else{  
  echo "Error in running query :". mysql_error();  
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top