0

i am using mysql_num_rows($query); function to get the total number of rows from table. but it shows zero count.

This is my code

<form method="POST" action="processor.php">
<!-- start data table -->
   <table id="table1" class="table table-striped table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr><th>Video ID</th><th>Video Name</th></tr>
    </thead>
    <?php
        $access = $_SESSION['login'];
        if($access == "white"){
                $sql = "SELECT * FROM videos ORDER BY id DESC";
                $query = $conn->query($sql);
                // Return the number of rows in result set
                $rowcount=mysql_num_rows($query);
                printf("Result set has %d rows.\n",$rowcount);
                      $i=1;
                      while ($row = $query->fetch(PDO::FETCH_ASSOC)){
                      $id = $row['id'];
                      $video_name = $row['video_name'];
                      echo "
                          <tbody>
                             <tr>
                               <td style='text-align:center;'>$id</td>
                               <td id='test10' class='text-center'><b>$video_name</b></td>
                             </tr>
                          </tbody>";
                   } $i++;
              }
       else {
             header ("location:index.php");
            }
         ?>
   </table>
   <!-- End data table -->  
 </form>    

i want to get the number of count of rows from this statement in above code.

 printf("Result set has %d rows.\n",$rowcount);

my result image is also attached.it just shows 0 rows. but my data is shown below image. its not zero. please help how to get count. thanks in advance

this is the result when i run above code. it shows 0 rows

jarlh
  • 42,561
  • 8
  • 45
  • 63
mohsin_sharif57
  • 39
  • 3
  • 13

2 Answers2

1

You use the PDO database module to fetch your data. I know it because of this line $query->fetch(PDO::FETCH_ASSOC). Please read the Doku how to fetch the row count if you use the pdo module.

T Schi
  • 116
  • 1
  • 6
1

By using this statement of PDO i get the total number of count.

$rowcount = $query->rowCount(); 
mohsin_sharif57
  • 39
  • 3
  • 13