请有人帮我解释一下为什么这不起作用。我正在检查是否存在带有计数的记录。如果退出则不添加新,如果不添加则允许。
<?php
// Setting a value for the new week to be added
$TeamOwner = $teams->MemberID->CurrentValue;
$OldWeek = $teams->WeekID->CurrentValue;
$NewWeek = ($OldWeek+1);
echo $NewWeek;
$con=mysqli_connect("localhost","root","","soccer_team");
// Check connection
if (mysqli_connect_errno())
{
throw new Exception(mysqli_connect_error(), mysqli_connect_errno());
getPosts($con); "Please try again later: " . mysqli_connect_error();
} else {
$result = mysqli_query($con,"SELECT COUNT(*) c FROM teams WHERE MemberID= $TeamOwner AND WeekID= $NewWeek");
$row = mysqli_fetch_array($result);
$row = $result->fetch_row();
$total = $row[0];
echo "No of Teams created this week: " . $total;
mysqli_close($con);
}
switch ($total)
{
case ($total== 0):
?><script> document.getElementById('btnAction').disabled = true; </script><?php
break;
case ($total == 1):
echo 'You cannot create another team, please update your existing team';
break;
}
?>
最佳答案
您从结果集中获取两次:
$row = mysqli_fetch_array($result);
$row = $result->fetch_row();
您需要删除其中之一。
关于php - MYSQLi Select 语句 - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602655/