Click here to Skip to main content
15,887,420 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to add these code down below to the WordPress post through php snippets plugin but, i stuck in this error in line number 13 and 41.

What I have tried:

echo '<a class="bg-danger btn btn-default" href="index.php" '; 
global $post, $wpdb;
 if( !isset($_GET['char']) ){
  echo ' class="active" ';
 }
 echo ' >All</a></li>';
 // Select Alphabets and total records
 $alpha_sql = "select DISTINCT LEFT(title , 1) as firstCharacter,
  ( select count(*) from products where LEFT(title , 1)= firstCharacter ) AS counter 
  from products 
  order by title asc";
 $result_alpha = mysqli_query($wpdb->dbh,$alpha_sql);
 while($row_alpha = mysqli_fetch_array($result_alpha)){
  $firstCharacter = $row_alpha['firstCharacter'];
  $counter = $row_alpha['counter'];
  echo '<a class="btn btn-default" href="?char='.$firstCharacter.'" '; 
  if( isset($_GET['char']) && $firstCharacter == $_GET['char'] ){
   echo ' class="active" ';
  }
  echo ' >'.$firstCharacter.'</a></li>';
 }
 ?>
  <?php
  // selecting rows
  $sql = "SELECT * FROM products where 1"; 
  if( isset($_GET['char']) ){
   $sql .= " and LEFT(title,1)='".$_GET['char']."' ";
  }
  $sql .=" ORDER BY title ASC";
  $result = mysqli_query($wpdb->dbh,$sql);
  $sno = 1;
  while($fetch = mysqli_fetch_array($result)){
   $title = $fetch['title'];
   $meaning = $fetch['meaning'];
   $description = $fetch['description'];
  ?>
  <tbody>
  <tr>
    <td><?php echo $sno; ?></td>
    <td><?php echo $title; ?></td>
    <td><?php echo $meaning; ?></td>
    <td><?php echo $description; ?></td>
  </tr>
</tbody>
      <?php
   $sno ++;
  } ?>
 </table>
Posted
Updated 14-Dec-18 23:06pm
Comments

1 solution

This is one of the most common questions we see on MySQL. Please refer to the documentation to see why the result of a query may be a boolean value of FALSE.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900