title: get count of fields with a specific value ? :mysql-php
body: <p>I'm trying to get a count of number of payments(PAID) from the table.</p>
  
  <pre><code>Please Assume This is the table:
  
  | book_no | name | mobile | date1 | date2 | date3 | date4 |.. daten |
  |---------|------|--------|-------|-------|-------|-------|-------|
  |    1    | Cell |        | PAID  | DUE   | DUE   |       |       |
  |    2    | Cell |        | PAID  | PAID  | PAID  |       |       | 
  |    3    | Cell |        | DUE   | DUE   | DUE   | DUE   |       |
  |    4    | Cell |        | PAID  | PAID  | PAID  |       |       | 
  |    5    | Cell |        | DUE   | DUE   | DUE   |       |       |
  </code></pre>
  
  <p>In the above table Count(Paid) = 7 </p>
  
  <p>The number of date columns is dynamic so I think it's wiser to search the entire table and get the PAID count. </p>
  
  <p>this is the code I managed to write referring answers on Stack overflow but it I don't think it's the right one for this</p>
  
  <pre><code>        //what is the search?
          $search = "PAID";
          //get all the columns
  
      $columnsq ="SELECT
                  COLUMN_NAME
                  FROM
                  information_schema.COLUMNS
                  WHERE TABLE_NAME = " .$scheme_name. "
                  AND TABLE_SCHEMA = 'gold' ";
  
              var_dump($columns);
          //put each like clause in an array
          $queryLikes = array();
          while ($column = $columns-&gt;fetch_assoc()) {
              $queryLikes[] = $column['COLUMN_NAME'] . " LIKE '%$search%'";
          }
  
          $query = "SELECT COUNT(*) FROM " .$scheme_name. "  WHERE " . implode(" OR ", $queryLikes);
          //echo $query; //should look like this:
          //SELECT * FROM users WHERE column1 LIKE '%something%' OR column2 LIKE '%something%' OR column3 LIKE '%something%' OR ...
          //so then
          $users=mysqli_query($conn,$query);
          while ($user = $users-&gt;fetch_assoc()) {
              //do stuff with $user
                  echo $users;
          }
  </code></pre>
  
  <p>I get this error when I try to execute the above code</p>
  
  <pre><code>                Notice: Undefined variable: columns in E:\xampp\htdocs\schemeTable11.php on line 391
  NULL 
  Notice: Undefined variable: columns in E:\xampp\htdocs\schemeTable11.php on line 394
  
  Fatal error: Uncaught Error: Call to a member function fetch_assoc() on null
  </code></pre>
  
  <p>therefore I'm looking for alternative solutions. 
   <strong><em>Please Help</em></strong></p>