Printing data from DB in WordPress not working

I am trying to print data from the database to WordPress. However, it is not working as expected. I also tried to print a simple variable.

$host="localhost"; // Host name
$username="root"; // username
$password=""; // password
$db_name="bk"; // Database name
// Replace database connect functions depending on database you are using.
mysql_connect("$host", "$username", "$password");
mysql_select_db($db_name);
$tbl_nm="rg";
global $wpdb;
$a=6;
$B=9;
$result = $wpdb->get_results ( "SELECT nm FROM rg" );
foreach ( $result as $print )   {
?><tr><td><?php
echo $print->nm;
print $a+$B;
?></td>
</tr>
<?php }

Related posts

1 comment

  1. hey,,i sloved my problem actually i m not assign ‘mysql_connect()’ to any veriable

    here is my code

      $host="localhost"; // Host name
      $username="root"; // username
      $password=""; // password
      $db_name="bk"; // Database name
    
      // Replace database connect functions depending on database you are using.
      $con=mysqli_connect("$host", "$username", "$password","$db_name");
    
    
    
         $tbl_nm="rg";
         global $wpdb;
         $result = mysqli_query($con,"SELECT * FROM rg" );
         while($row = mysqli_fetch_array($result))
         {echo '    <td colspan="0">'.$row['nm'].'</td>';}
        ?>
    

Comments are closed.