Alphabetical filter in table not working
<p>I have created a table with alphabet filter in PHP. It was working fine without any issue. BUT i was developing it for wordpress project, So after successfully development in PHP I tried to imliment it in wordpress using <code>$wpdb</code>. </p>

<p>The problem I am facing now is that to filter we need to click any alphabet (suppose A) And after clicking All enteries that started from 'A' should return as output. But instead of returning Only 'A' entries Its returning whole table. In short filter is not working.</p>

<p>I am using this code in template file in wordpress.</p>

<pre><code>global $wpdb;
?&gt;&lt;div class="wrap"&gt;&lt;div class="main-top"&gt;&lt;div class="main"&gt;&lt;h1&gt;&lt;div    class="titlepage"&gt;&lt;?php the_title();?&gt;&lt;/div&gt;&lt;/h1&gt;&lt;?php
?&gt;&lt;form action="memberspage.php" method="POST" name='search'  onclick="submit"&gt;
&lt;a href="?page_id=911?letter=A"&gt;A&lt;/a&gt; |
&lt;a href="?page_id=911?letter=B"&gt;B&lt;/a&gt; |
&lt;a href="?page_id=911?letter=C"&gt;C&lt;/a&gt; |
&lt;a href="?page_id=911?letter=D"&gt;D&lt;/a&gt; |
&lt;a href="?page_id=911?letter=E"&gt;E&lt;/a&gt; |
&lt;a href="?page_id=911?letter=F"&gt;F&lt;/a&gt; |
&lt;a href="?page_id=911?letter=G"&gt;G&lt;/a&gt; |
&lt;a href="?page_id=911?letter=H"&gt;H&lt;/a&gt; |
&lt;a href="?page_id=911?letter=I"&gt;I&lt;/a&gt; |
&lt;a href="?page_id=911?letter=J"&gt;J&lt;/a&gt; |
&lt;a href="?page_id=911?letter=K"&gt;K&lt;/a&gt; |
&lt;a href="?page_id=911?letter=L"&gt;L&lt;/a&gt; |
&lt;a href="?page_id=911?letter=M"&gt;M&lt;/a&gt; |
&lt;a href="?page_id=911?letter=N"&gt;N&lt;/a&gt; |
&lt;a href="?page_id=911?letter=O"&gt;O&lt;/a&gt; |
&lt;a href="?page_id=911?letter=P"&gt;P&lt;/a&gt; |
&lt;a href="?page_id=911?letter=Q"&gt;Q&lt;/a&gt; |
&lt;a href="?page_id=911?letter=R"&gt;R&lt;/a&gt; |
&lt;a href="?page_id=911?letter=S"&gt;S&lt;/a&gt; |
&lt;a href="?page_id=911?letter=T"&gt;T&lt;/a&gt; |
&lt;a href="?page_id=911?letter=U"&gt;U&lt;/a&gt; |
&lt;a href="?page_id=911?letter=V"&gt;V&lt;/a&gt; |
&lt;a href="?page_id=911?letter=W"&gt;W&lt;/a&gt; |
&lt;a href="?page_id=911?letter=X"&gt;X&lt;/a&gt; |
&lt;a href="?page_id=911?letter=Y"&gt;Y&lt;/a&gt; |
&lt;a href="?page_id=911?letter=Z"&gt;Z&lt;/a&gt; |
&lt;a href="?page_id=911"&gt;View All&lt;/a&gt; 
&lt;/form&gt;&lt;?php
if(isset($_GET['letter']))
{
  $char=$_GET['letter'];

  if($char)
{
$sql = $wpdb-&gt;get_results( "SELECT * FROM teacher_directory where Name LIKE     '$char%'", ARRAY_A  );
$count = $sql-&gt;num_rows;
if($count &gt;= 1)
{
    echo "&lt;table width='100%' border='1'&gt;";
    echo "&lt;tbody&gt;";
    echo "&lt;tr&gt;";
    echo "&lt;th&gt;S. No.&lt;/th&gt;";
    echo "&lt;th&gt;Name&lt;/th&gt;";
    echo "&lt;th&gt;Designation&lt;/th&gt;";
    echo "&lt;th&gt;Department&lt;/th&gt;";
    echo "&lt;th&gt;Tele/Mob.No.&lt;/th&gt;";
    echo "&lt;/tr&gt;";
    foreach($sql as $row){
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $row['S. No.'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Name'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Designation'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Department'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Tele/Mob.No.'] . "&lt;/td&gt;";               
    echo "&lt;/tr&gt;";
 }
    echo "&lt;/tbody&gt;";
    echo "&lt;/table&gt;"; 
}}
}
</code></pre>

<blockquote>
  <p>UPDATE   -: Since I got my answer, I am showing my final complete code(in working condition) for future viewers</p>
</blockquote>

<p>If anyone is facing issue regarding Alphabetical filtered table then below code may solve your problem. It can be use in template file.</p>

<pre><code>&lt;?php
/*
Template Name: Table
*/
get_header();
?&gt;&lt;div class="banner-box"&gt;&lt;?php
global $wpdb;
?&gt;&lt;div class="wrap"&gt;&lt;div class="main-top"&gt;&lt;div class="main"&gt;&lt;h1&gt;&lt;div  class="titlepage"&gt;&lt;?php the_title();?&gt;&lt;/div&gt;&lt;/h1&gt;&lt;div class="contcolor"&gt;&lt;?php
?&gt;&lt;form action="teacher.php" method="POST" name='search' onclick="submit"&gt;&lt;a  href="?page_id=916&amp;letter=A"&gt;A&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=B"&gt;B&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=C"&gt;C&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=D"&gt;D&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=E"&gt;E&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=F"&gt;F&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=G"&gt;G&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=H"&gt;H&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=I"&gt;I&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=J"&gt;J&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=K"&gt;K&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=L"&gt;L&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=M"&gt;M&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=N"&gt;N&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=O"&gt;O&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=P"&gt;P&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=Q"&gt;Q&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=R"&gt;R&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=S"&gt;S&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=T"&gt;T&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=U"&gt;U&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=V"&gt;V&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=W"&gt;W&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=X"&gt;X&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=Y"&gt;Y&lt;/a&gt; |
&lt;a href="?page_id=916&amp;letter=Z"&gt;Z&lt;/a&gt; |
&lt;a href="?page_id=916"&gt;View All&lt;/a&gt; 
&lt;/form&gt;&lt;?php
if(isset($_GET['letter']))
{
  $char=$_GET['letter'];
  if($char)
{
$results = $wpdb-&gt;get_results( "SELECT * FROM teacher_directory where Name     LIKE '$char%'", ARRAY_A  );
$count = $results-&gt;num_rows;
?&gt;&lt;div class="contcolor"&gt;&lt;?php
if(!empty($results))
{   
    echo "&lt;table width='100%' border='1' cellspacing='1'&gt;";
    echo "&lt;tbody&gt;";
    echo "&lt;tr&gt;";
    echo "&lt;th&gt;S. No.&lt;/th&gt;";
    echo "&lt;th&gt;Name&lt;/th&gt;";
    echo "&lt;th&gt;Designation&lt;/th&gt;";
    echo "&lt;th&gt;Department&lt;/th&gt;";
    echo "&lt;th&gt;Tele/Mob.No.&lt;/th&gt;";
    echo "&lt;/tr&gt;";
    foreach($results as $row){
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;" . $n +=1 . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Salutation'].' '.$row['Name'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Designation'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Department'] . "&lt;/td&gt;";
    echo "&lt;td&gt;" . $row['Tele/Mob.No.'] . "&lt;/td&gt;";               
    echo "&lt;/tr&gt;";
 }
  echo "&lt;/tbody&gt;";
  echo "&lt;/table&gt;"; 
}else
{
  echo "&lt;table width='100%' border='1' cellspacing='1'&gt;&lt;tr&gt;&lt;td&gt;No Records    Found&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";
}?&gt;&lt;/div&gt;&lt;?php
}}

else {

       $results = $wpdb-&gt;get_results( 'SELECT * FROM teacher_directory', ARRAY_A  );
       if(!empty($results)){
       ?&gt;&lt;div class="contcolor"&gt;&lt;?php
        echo "&lt;table width='100%' border='1' cellspacing='1'&gt;";
       echo "&lt;tbody&gt;";
       echo "&lt;tr&gt;";
       echo "&lt;th&gt;S. No.&lt;/th&gt;";
       echo "&lt;th&gt;Name&lt;/th&gt;";
       echo "&lt;th&gt;Designation&lt;/th&gt;";
       echo "&lt;th&gt;Department&lt;/th&gt;";
       echo "&lt;th&gt;Tele/Mob.No.&lt;/th&gt;";
       echo "&lt;/tr&gt;";
       foreach($results as $row){
       echo "&lt;tr&gt;";
       echo "&lt;td&gt;" . $row['S. No.'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Salutation'].' '.$row['Name'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Designation'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Department'] . "&lt;/td&gt;";
       echo "&lt;td&gt;" . $row['Tele/Mob.No.'] . "&lt;/td&gt;";               
       echo "&lt;/tr&gt;";
 }
 echo "&lt;/tbody&gt;";
 echo "&lt;/table&gt;"; 
 ?&gt;&lt;/div&gt;&lt;?php
}}
?&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;?php
get_footer();?&gt;&lt;/div&gt;
</code></pre>