gpt4 book ai didi

php - 创建 2x1 矩阵系统

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

我创建了 2x1 矩阵系统,其中一个人捐款,捐款后他会收到两个人的钱。我正在尝试创建一种情况,其中一个人第一次进入系统(注册后),系统将检查系统中是否有任何人可以从该人处接收资金(如果有)那么我正在检查该人是否已经收到两次付款,如果该人收到两次付款,系统将检查系统中的下一个人,并将再次进行该过程以检查该人是否已收到两次。现在的问题是,系统只检查 2 个人,例如系统是否正在找到一个人,并且该人已经复活两次,付款系统将转到下一个,但如果下一个已收到,则系统应该转到下一个,依此类推,除非他找到用户或没有用户。但我的系统最多只能容纳两个人,我不知道应该如何创建一个循环,以便系统检查数据库中的整个用户。

public function allotDonar($id) {
$date = date('Y-m-d h:i:s a');
$currentDate = strtotime($date);
$futureDate = $currentDate+(60*1);
$formatDate = date("Y-m-d h:i:s a", $futureDate);
$endDate = date("Y-m-d h:i:s a", strtotime('+30 hours'));

$get = $this -> db -> query("Select user.id, user.super, user.name,
user.canRecieve, user.active, user.blocked, user_packages.packageID, user.type,
user_packages.userID from (Select user.id AS USERID, canRecieve, type, super,
status, packageID, active from user JOIN user_packages ON user.id='$id' AND
user.type='0' AND user.super='0' AND user.canRecieve='0' AND user.active='1' AND
user_packages.userID=user.id AND user_packages.status='1') AS DONOR JOIN user ON
user.id!='$id' AND user.canRecieve='1' AND user.active='1' AND user.blocked='0'
AND user.type='0' AND user.super='0' JOIN user_packages ON
user.id=user_packages.userID AND user_packages.status='1' AND
user_packages.packageID=DONOR.packageID ORDER BY user.id ASC");
if($get -> num_rows() > 0) {
$UserInfo = $get -> row();
$key = $get -> result();
$sql = "Select * from donar where packageID=? AND reciever_id=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $UserInfo -> id));
// return $query -> result();
if($query -> num_rows() >= 2) {
// return 'Persons';
// if user cycle has not been completed but user has tow recievings in the table then again search fot the next user in the array
$nexPerson = current(array_slice($key, array_search($key, array_keys($key)) + 1, 1));
if(!empty($nexPerson)) {
$nextPersonID = $nexPerson -> id;
// check if next pserons has paid money or not
$checkIfNextPaid = $this -> db -> query("Select * from user where canRecieve='1'");
if($checkIfNextPaid -> num_rows() > 0) {
$sql = "Select * from donar where packageID=? AND reciever_id=?";
$query = $this -> db -> query($sql, array($nexPerson -> packageID, $nexPerson -> id));
// return $query -> result();
if($query -> num_rows() >= 2) {
//$this -> allotDonar($id);
}
else {

$sql = "Select * from donar where packageID=? AND donarID=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $id));
if($query -> num_rows() >= 1) {
}
else {
// $currentID = $UserInfo -> id;
$allotDonar = $this -> db -> insert('donar', array('donarID' => $id, 'reciever_id' => $nexPerson -> id, 'packageID' => $nexPerson -> packageID, 'date_added' => $date, 'date_expiry' => $endDate, 'wait_time' => $formatDate, 'wait_start' => $date));
return $this -> db -> insert_id();
}
}
}
}
}
else {
$sql = "Select * from donar where packageID=? AND donarID=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $id));
if($query -> num_rows() >= 1) {
}
else {
// if the rows of the user are less then 2 record then simply insert the erecord of the user
$allotDonar = $this -> db -> insert('donar', array('donarID' => $id, 'reciever_id' => $UserInfo -> id, 'packageID' => $UserInfo -> packageID, 'date_added' => $date, 'date_expiry' => $endDate, 'wait_time' => $formatDate, 'wait_start' => $date));
return $this -> db -> insert_id();
}
}
}
else {
return 'No person found';
}

请帮助我让这个系统检查数据库中的整个用户。

最佳答案

我找到了解决办法

public function allotDonar($id) {
$date = date('Y-m-d h:i:s a');
$currentDate = strtotime($date);
$futureDate = $currentDate+(60*1);
$formatDate = date("Y-m-d h:i:s a", $futureDate);
$endDate = date("Y-m-d h:i:s a", strtotime('+30 hours'));

$get = $this -> db -> query("Select user.id, user.super, user.name, user.canRecieve, user.active, user.blocked, user_packages.packageID, user.type, user_packages.userID from (Select user.id AS USERID, canRecieve, type, super, status, packageID, active from user JOIN user_packages ON user.id='$id' AND user.type='0' AND user.super='0' AND user.canRecieve='0' AND user.active='1' AND user_packages.userID=user.id AND user_packages.status='1') AS DONOR JOIN user ON user.id!='$id' AND user.canRecieve='1' AND user.active='1' AND user.blocked='0' AND user.type='0' AND user.super='0' JOIN user_packages ON user.id=user_packages.userID AND user_packages.status='1' AND user_packages.packageID=DONOR.packageID ORDER BY user.id ASC");
if($get -> num_rows() > 0) {
$UserInfo = $get -> row();
$key = $get -> result();
$sql = "Select * from donar where packageID=? AND reciever_id=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $UserInfo -> id));
// return $query -> result();
if($query -> num_rows() >= 2) {
// return 'Persons';
// if user cycle has not been completed but user has tow recievings in the table then again search fot the next user in the array
$next = 1;
for ($i = 1; $i < count($key); $i++) {
$nexPerson = current(array_slice($key, array_search($key, array_keys($key)) + $i, 1));
$found = $this -> findNextPerson($UserInfo, $nexPerson, $id);
}
}
else {
$sql = "Select * from donar where packageID=? AND donarID=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $id));
if($query -> num_rows() >= 1) {
// return false
}
else {
// if the rows of the user are less then 2 record then simply insert the erecord of the user
$allotDonar = $this -> db -> insert('donar', array('donarID' => $id, 'reciever_id' => $UserInfo -> id, 'packageID' => $UserInfo -> packageID, 'date_added' => $date, 'date_expiry' => $endDate, 'wait_time' => $formatDate, 'wait_start' => $date));
return $this -> db -> insert_id();
}
}
}
else {
return 'No person found';
}

}

function findNextPerson($UserInfo, $nexPerson, $id) {
$date = date('Y-m-d h:i:s a');
$currentDate = strtotime($date);
$futureDate = $currentDate+(60*1);
$formatDate = date("Y-m-d h:i:s a", $futureDate);
$endDate = date("Y-m-d h:i:s a", strtotime('+30 hours'));

if(!empty($nexPerson)) {
$nextPersonID = $nexPerson -> id;
// check if next pserons has paid money or not
$checkIfNextPaid = $this -> db -> query("Select * from user where canRecieve='1'");
if($checkIfNextPaid -> num_rows() > 0) {
$sql = "Select * from donar where packageID=? AND reciever_id=?";
$query = $this -> db -> query($sql, array($nexPerson -> packageID, $nexPerson -> id));
// return $query -> result();
if($query -> num_rows() >= 2) {
return 'Go back';
}
else {
$sql = "Select * from donar where packageID=? AND donarID=?";
$query = $this -> db -> query($sql, array($UserInfo -> packageID, $id));
if($query -> num_rows() >= 1) {
}
else {
// $currentID = $UserInfo -> id;
$allotDonar = $this -> db -> insert('donar', array('donarID' => $id, 'reciever_id' => $nexPerson -> id, 'packageID' => $nexPerson -> packageID, 'date_added' => $date, 'date_expiry' => $endDate, 'wait_time' => $formatDate, 'wait_start' => $date));
return $this -> db -> insert_id();
}
}
}
}
}

关于php - 创建 2x1 矩阵系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42904233/

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