如何获取 sql 搜索查询的计数?
How to get count of the sql search query?
如何获取 sql 搜索查询的计数
$u = new user();
$sql = "SELECT a.id FROM `accounts` AS a LEFT JOIN `users` AS u ON a.id = u.id WHERE a.id IS NOT NULL ";
$gender = $this->input->post('gender');
if($gender != NULL)
{
$sql .= "AND u.gender = '".$gender."' ";
}
$u->query($sql);
如何计算 $u->query($sql);
中的查询结果数。我需要对其设置验证。如果查询结果计数为 0 ,我需要设置一条消息。我正在使用 PHP Codeigniter,datamapper 库。
谢谢!!!
像这样使用 count() 函数
...
$result = $u->query($sql);
$total_data = count($result);
$result = $this->db->get();
For Codeigniter use $count = $result->num_rows(); // HERE IS YOUR COUNT
For OOP PHP use $count = $result->num_rows;
if($u->exists())
{
echo "Found" // Do something
}
else
{
echo "Nothing found" //Do something
}
如何获取 sql 搜索查询的计数
$u = new user();
$sql = "SELECT a.id FROM `accounts` AS a LEFT JOIN `users` AS u ON a.id = u.id WHERE a.id IS NOT NULL ";
$gender = $this->input->post('gender');
if($gender != NULL)
{
$sql .= "AND u.gender = '".$gender."' ";
}
$u->query($sql);
如何计算 $u->query($sql);
中的查询结果数。我需要对其设置验证。如果查询结果计数为 0 ,我需要设置一条消息。我正在使用 PHP Codeigniter,datamapper 库。
谢谢!!!
像这样使用 count() 函数
...
$result = $u->query($sql);
$total_data = count($result);
$result = $this->db->get();
For Codeigniter use $count = $result->num_rows(); // HERE IS YOUR COUNT
For OOP PHP use $count = $result->num_rows;
if($u->exists())
{
echo "Found" // Do something
}
else
{
echo "Nothing found" //Do something
}