有人请帮我解释为什么这不起作用。我正在检查记录是否存在计数。如果它退出没有添加新的,如果它不添加新的允许。
<?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;
}
?>
答案 0 :(得分:2)
您从结果集中取两次:
$row = mysqli_fetch_array($result);
$row = $result->fetch_row();
您需要删除其中一个。
答案 1 :(得分:-1)
也许将开始更改为MemberID并添加“as c”。
SELECT COUNT(MemberID) as c FROM teams WHERE MemberID= $TeamOwner AND WeekID= $NewWeek"