简体   繁体   中英

How do I count query result rows?

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:

    $con=mysqli_connect("localhost","mbrconsu_un394x","y1cz9,rd+hf6","mbrconsu_mmx");

    if (mysqli_connect_errno($con))
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $usuario = $con->real_escape_string($_GET['usuario']);
    $senha = $con->real_escape_string($_GET['senha']);

        $query = mysqli_query($con, "SELECT * FROM 'login' WHERE usuario = '$usuario' AND senha='$senha'");

        if(CODE TO VERIFY IF QUERY RESULT ROW IS = 1){
            while($row = mysqli_fetch_assoc($query)){
                $db_username = $row['usuario'];
                $db_password = $row['senha'];
            }
            if($usuario == $db_username && $senha == $db_password){
                return true;
            }
            } else {
            return false;
        }

    mysqli_close($con);
?>
$query->num_rows;

或者

mysqli_num_rows($query);

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

你也可以使用这个 sql 查询:

Select count(*) from table

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM