使用php获取对象的值
我有一个代码,用来获取包含当前用户ip地址的数据库中的行数,因此我编写了一个mysqli语句,它获取包含该ip地址的每一行,并将其存储在一个变量中。当我打印出变量时,它打印了以下内容:使用php获取对象的值,php,Php,我有一个代码,用来获取包含当前用户ip地址的数据库中的行数,因此我编写了一个mysqli语句,它获取包含该ip地址的每一行,并将其存储在一个变量中。当我打印出变量时,它打印了以下内容: mysqli_result Object ( [current_field] => 0 [field_count] => 7 [lengths] => [num_rows] => 2 [type] => 0 ) 如何访问对象中的num_行。
mysqli_result Object
(
[current_field] => 0
[field_count] => 7
[lengths] =>
[num_rows] => 2
[type] => 0
)
如何访问对象中的num_行
。
这是我的密码:
<?php
include("../functions/functions.php");
include("./db.php");
global $conn;
$ip = get_ip();
$select = "SELECT * FROM `cart` WHERE `ip_address`= '$ip' ";
$run_check_prod = mysqli_query($conn,$select);
if(mysqli_num_rows($run_check_prod) > 0) {
print_r($run_check_prod);
}
?>
您可以使用下面的代码获取PHP对象中的值num\u rows
。我实现了上面代码中用于获取对象值的代码
<?php
include("../functions/functions.php");
include("./db.php");
global $conn;
$ip = get_ip();
$select = "SELECT * FROM `cart` WHERE `ip_address`= '$ip' ";
$run_check_prod = mysqli_query($conn,$select);
if(mysqli_num_rows($run_check_prod) > 0) {
//the $run_check_prod is object and num_rows is key
echo $run_check_prod->num_rows;
}
?>
Wellecho$run\u check\u prod->num\u rows
但使用提供的函数,就像您已经使用的一样,或者echo$run\u check\u prod->num\u rows
您已经在这里获得了num\u rows
if(mysqli\u num\u rows($run\u check\u prod)
。您的问题是什么?