Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1009161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:52:58+00:00 2026-05-16T08:52:58+00:00

i’m trying to use mysqli to display data, but it displays nothing. what is

  • 0

i’m trying to use mysqli to display data, but it displays nothing.

what is wrong with my code?

php class:

/* the database object */
        private $_db;

        public function __construct($db=NULL)
        {
            if(is_object($db))
            {
                $this->_db = $db;
            }
            else
            {

                $this->_db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
            }
        }

        public function displayQuotes()
        {
            $sql = "SELECT cQuotes, vAuthor, cArabic, vReference 
                          FROM thquotes 
                          ORDER BY RAND()
                      LIMIT 1;";



                      $query = $this->_db->prepare($sql);
                      $query->execute();
                  $query->store_result();

                      /* bind variables to prepared statement */
                      $query->bind_result($cQuotes, $vAuthor, $cArabic, $vReference);


                      if(!$query->num_rows==0)
                      {
                        while($row = $query->fetch())
                        {
                            //echo $this->formatQuotes($row);
                            $formatHTML = new formatHTML();
                            echo $formatHTML->formatQuotes($row);
                        }


                      }
                      else
                         {
                            echo "There are no Quotes!";
                         }
                       $query->free_result();
                      $query->close();



        }

it does read the statement of if(!$query->num_rows==0) and data is there in the resultset since it does not go to the else part, but i cannot figure out why it isn’t displaying anything.

php file:

include "base.php";
include_once "inc/class.quotes-m.inc.php";
$quotes = new Quotes($db);

$quotes->displayQuotes();

php base.php:

include_once("inc/constants.inc.php");

error_reporting(E_ALL);
ini_set("display_errors", 1);



        $db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

         if (!$db) {
            echo 'db link fail';
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:52:58+00:00Added an answer on May 16, 2026 at 8:52 am

    ! has a higher precedence than ==, i.e.

    if(!$query->num_rows==0) { ... }
    // is equivalent to
    if( (!$query->num_rows) == 0 ) { ... }
    

    i.e. $query->num_rows is logically negated (involving an int->bool cast) then this boolean value is compared to 0.

    But you want something like

    if( 0 < $query->num_rows ) { ... }
    

    You’re using a try { … } catch() block. But the mysqli extension doesn’t throw exceptions (IIRC). Unless $this->_db is some kind of (additional) wrapper you have to test the return values of the mysqli methods, or use an api that actually throws an exception when an error occurs like e.g. PDO (when setting the error mode to PDO::ERRMODE_EXCEPTION).


      public function displayQuotes()
      {
        $sql = "
          SELECT cQuotes, vAuthor, cArabic, vReference
          FROM thquotes
          ORDER BY RAND()
          LIMIT 1
        ";
    
        $query = $this->_db->prepare($sql);
        if ( !$query ) {
          throw new ErrorException($this->_db->error, $this->_db->errno);
        }
        $r = $query->execute();
        if ( !$r ) {
          throw new ErrorException($query->error, $query->errno);
        }
    
        $r = $query->store_result();
        if ( !$r ) {
          throw new ErrorException($query->error, $query->errno);
        }
    
        /* bind variables to prepared statement */
        $r = $query->bind_result($cQuotes, $vAuthor, $cArabic, $vReference);
        if ( !$r ) {
          throw new ErrorException($query->error, $query->errno);
        }
    
        if( 0 < $query->num_rows ) {
          $formatHTML = new formatHTML();
          while( false!==($row=$query->fetch()) ) {
            echo $formatHTML->formatQuotes($row);
          }
        }
        else {
          echo "There are no Quotes!";
        }
        $query->free_result();
        $query->close();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.