代码中的问题,不能在PHP中重复相同的数字
问题描述:
Hello guys
我写了这个函数,返回数据库中同一天不能存在的时间(数字),这意味着同一时间不能重复但是当我执行它的时间(数字)重复
你可以帮我解决这个吗?
注意:表是空的它将在整个代码执行时填写我刚刚发布的功能,不得重复该时间。
Hello guys
I've wrote this function that returns a time(number )that must not exist in the same day in the database which means that the same time must not be repeated but when i execute it the time(number) is repeated
can you help me sort this one out?
note: the table is empty and it will be filled when the entire code is executed i have just posted the function that must not repeat the time.
function checkTime($className,$day,$conn){
global $numberLimet,$Daily,$UserLimt,$exist;
$sqlHoure = "SELECT * from schedule WHERE classname='".$className."'";
$hourQuery = mysqli_query($conn,$sqlHoure);
$h = array();
while ($hour = mysqli_fetch_assoc($hourQuery)){
$h[$hour['hour']] = $hour['day1'];
// array_search();
}
$number = rand(1,7);
if(array_search($day,$h) && array_key_exists($number,$h)){
return 'error';
}else{
if($hour['hour'] != $number && $hour['day1'] != $day){
$numberLimet++;
if($numberLimet == $Daily){
$UserLimt = 1;
$FristAdd = false;
echo("UserLimt" . $UserLimt);
return 'errorLimit';
}else{
return $number;
}
}else{
}
//
}
return $h;
}
我的尝试:
i尝试多次更改代码,但结果相同
What I have tried:
i tried to change the code many times but the same result
答
className,
className,
day,
conn){
global
conn){ global