How do I count query result rows?

前端 未结 4 604
醉梦人生
醉梦人生 2020-11-27 08:12

What should I replace \'CODE TO VERIFY IF QUERY RESULT ROW IS = 1\' for?
I\'ve tried many ways using num_rows but it won\'t work.

My PHP code:

         


        
相关标签:
4条回答
  • 2020-11-27 08:56

    you could just do

        if($row = mysqli_fetch_assoc($query)) {
    
        }
    

    also you may want to save your username and password in one file as constants

    0 讨论(0)
  • 2020-11-27 09:06
    $query->num_rows;
    

    or

    mysqli_num_rows($query);
    
    0 讨论(0)
  • 2020-11-27 09:07

    You can use:

    $stmt=$mysqli->prepare("select `id` from `agahicustomer` where `city`=?");
        $stmt->bind_param("s",$cityid);
        $stmt->execute();
        $stmt->store_result();
        $stmt->bind_result($id);
        return $stmt->affected_rows;
        $stmt->close();
    
    0 讨论(0)
  • 2020-11-27 09:09

    Also you can use this sql query :

    Select count(*) from table
    
    0 讨论(0)
提交回复
热议问题