我有以下代码来计算数据库中的行数并将结果返回给用户:
// Connect to database and select
$mysqli = mysqli_connect($config['db_hostname'], $config['db_username'], $config['db_password'], $config['db_name']);
$mysqli->set_charset('utf8');
$select = 'SELECT COUNT(*) AS wines FROM ft_form_4 WHERE feu_id = "'.$feuid.'"';
$response = mysqli_query($mysqli, $select) or die("Error: ".mysqli_error($mysqli));
$result = mysqli_fetch_array($response, MYSQLI_ASSOC);
$wines = (int)$result[wines];
echo $wines;
// Return 0 for no entries
if ($wines = 0) {
echo 'You currently have no wines entered, your current total entry fee is <strong>£0</strong>.';
}
elseif ($wines = 1) {
echo 'You currently have 1 wine entered, your current total entry fee is <strong>£135</strong>.';
}
elseif ($wines > 1) {
$fee = $wines * 135;
echo 'You currently have '.$wines.' wines entered, your current total entry fee is <strong>'.$fee.'</strong>.';
}
当我运行代码时,结果在第一位(我刚刚输入以进行测试)回显为 3,这是正确的,但它始终显示第二行,表示输入了一种葡萄酒,入场费为 £ 135. 它似乎没有将 3 识别为数字。
我已经使用 mysqli_num_rows 尝试了第二批代码,但我也没有任何运气。