gpt4 book ai didi

PHP sql server 获取行数

转载 作者:行者123 更新时间:2023-11-29 21:05:25 25 4
gpt4 key购买 nike

我正在尝试从 MySQL 语句获取行数并创建 if-else 语句。然而,我尝试了几次,但似乎不起作用。谁能告诉我我做错了什么?或者有没有更好的方法来做到这一点。

PHP:

    $sqlquery_str = "SELECT * FROM Promotions WHERE membershipType = :membershipType AND promoStatus = '1' AND CONVERT(datetime, startDate, 103)  <= convert(varchar(8), GETDATE(), 112) AND CONVERT(datetime, endDate, 103)  >= convert(varchar(8), GETDATE(), 112) AND startTime <= CONVERT(char(5), GETDATE(),108) AND endTime >= CONVERT(char(5), GETDATE(),108)";

$number_of_rows = mysql_fetch_array($sqlquery_str);
$total = $number_of_rows[0];

If else 语句:

    if (!$results){
logError('SQL Query failed',print_r($conns->errorInfo(),true));
echo '
<b>There was an error retrieving the information for the selected event. Please contact the administrator for further advice.</b>';
}

else if ($total == 1){
echo "There is an error";
echo "<br />";
}

else {
$DOMstr = "<h1 class='post-title'>".$results['titlePromo']."</h1>";
}

最佳答案

使用mysql_num_rows()

<?php
$sqlquery_str = "SELECT * FROM Promotions WHERE membershipType = :membershipType AND promoStatus = '1' AND CONVERT(datetime, startDate, 103) <= convert(varchar(8), GETDATE(), 112) AND CONVERT(datetime, endDate, 103) >= convert(varchar(8), GETDATE(), 112) AND startTime <= CONVERT(char(5), GETDATE(),108) AND endTime >= CONVERT(char(5), GETDATE(),108)";

$number_of_rows = mysql_num_rows($sqlquery_str);

if ($number_of_rows > 0)
{
$results = mysql_fetch_array($sqlquery_str);
$DOMstr = "<h1 class='post-title'>".$results['titlePromo']."</h1>";
}
else
{
echo "There is an error";
echo "<br />";
}
?>

关于PHP sql server 获取行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36859115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com