vignesh warar February 2016

num_rows Always shows Zero value in PHP/MYSQL?

I am totally new to this PHP.

I am just practicing Prepared statements. I know there few questions which is related to mine.

But nothing Helped me.

This is my php code Which returns always num_rows equal to Zero.

But there is a data in my table

   if (isset($_POST['submit'])) {
                        $my_id = 49;
                        $content = $_POST['cont'];
                        $content_date = date('d-m-y');
                        $check = "SELECT * FROM post WHERE user_id = ?";
                        $stmt = $con->prepare($check);
                        $stmt->bind_param("i",$my_id);
                        $stmt->execute();
                        $stmt->fetch();
                        $numberofrows = $stmt->num_rows;
                        $stmt->close();
                        echo '<h1>'.$numberofrows.'</h1>';


                     }

Answers


Ashish Patel February 2016

Use () look like this... $numberofrows = $stmt->num_rows(); and try.


vignesh warar February 2016

Guys Thanx For your Ans Finally My friend helped me to solve this. We have to store the result before we calling num_rows

$stmt->store_result(); 

It works fine now

Post Status

Asked in February 2016
Viewed 2,572 times
Voted 12
Answered 2 times

Search




Leave an answer