我有一个 php 脚本从 mysql 数据库执行搜索记录,如何添加从 mysql 查询返回的总计数?例如。我搜索“ABC”,总搜索结果为 3,我想在搜索“找到的总搜索数:3”后显示此结果。到目前为止一直在尝试下面的代码,但没有取得任何好的进展,任何人都可以提供帮助吗?谢谢
<?php
define('DB_HOST', 'localhost');
define('DB_NAME', 'stock');
define('DB_CHARSET', 'utf8mb4');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
try
{
$pdo = new PDO("mysql:host=" . DB_HOST . ";charset=" . DB_CHARSET . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false]);
}
catch(Exception $ex)
{
die($ex->getMessage());
}
$stmt = $pdo->prepare("SELECT * FROM `data` WHERE `Name` LIKE ? OR `shopfront_signage` LIKE ? ");
$stmt->execute(["%" . $_POST['search'] . "%", "%" . $_POST['search'] . "%"]);
$results = $stmt->fetchAll();
if (isset($_POST['ajax']))
{
echo json_encode($results);
}
//$resultscount= $results[0];
//echo $resultscount;
$query = mysqli_query($stmt);
$resultrow = mysqli_num_rows($query);
echo 'Total search found: ' . $resultrow;
?>
蝴蝶刀刀
料青山看我应如是