我试图将函数的操作数减少到只有一个查询,但现在我无法检索任何结果:
function retrive_avaible_operator($Hostname, $Username, $Password, $DatabaseName, $SupportUserPerDepaTable, $SupportUserTable,$dep){
$query = "SELECT b.id
FROM ".$SupportUserTable." b
INNER JOIN ".$SupportUserPerDepaTable." a
ON b.id=a.user_id
WHERE a.department_id=? AND b.holiday='0' AND a.user_id!=".$_SESSION['id']."
ORDER BY b.assigned_tickets ASC LIMIT 1";
$mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
$stmt = $mysqli->stmt_init();
$prepared = $stmt->prepare($query);
if($prepared){
if($stmt->bind_param('i', $dep)){
if($stmt->execute()){
$stmt->store_result();
$result = $stmt->bind_result($camaro);
if($stmt->num_rows>0){
while (mysqli_stmt_fetch($stmt))
$selopid=$camaro;
return $selopid;
}
else
return 'No Operator Available';
}
else
return mysqli_stmt_error($stmt);
}
else
return mysqli_stmt_error($stmt);
}
else
return mysqli_stmt_error($stmt);
}
在此尝试之前,操作是(这些是 2 个不同的查询):
$SupportUserPerDepaTable
从哪里选择所有ida.department_id=?
- 选择 id
$SupportUserTable
在先前结果中的所有 id 和holiday='0'
它有效,但现在它只返回No Operator Available
还有这些表格:
CREATE TABLE IF NOT EXISTS `razorphyn_support_user_departments` (
`id` BIGINT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`department_id` BIGINT(11) UNSIGNED NOT NULL,
`department_name` VARCHAR(70) NOT NULL,
`user_id` BIGINT(11) UNSIGNED NOT NULL,
`holiday` ENUM('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY(`department_name`,`user_id`),
INDEX(`department_id`,`department_name`,`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
和
CREATE TABLE IF NOT EXISTS `razorphyn_support_users` (
`id` BIGINT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`mail` VARCHAR(50) NOT NULL,
`password` VARCHAR(200) NOT NULL,
`reg_key` VARCHAR(260) ,
`tmp_password` VARCHAR(87) ,
`ip_address` VARCHAR(50) NOT NULL,
`status` ENUM('0','1','2','3','4') NOT NULL DEFAULT '3',
`holiday` ENUM('0','1') NOT NULL DEFAULT '0',
`mail_alert` ENUM('no','yes') NOT NULL DEFAULT 'yes',
`assigned_tickets` INT(5) UNSIGNED NOT NULL DEFAULT 0,
`solved_tickets` BIGINT(11) UNSIGNED NOT NULL DEFAULT 0,
`number_rating` BIGINT(6) UNSIGNED NOT NULL DEFAULT 0,
`rating` DECIMAL(4,2) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`mail`),
INDEX (`name`,`mail`,`status`,`holiday`,`assigned_tickets`,`solved_tickets`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=55;
编辑
我发现(不幸的是,因为非常丑陋和凌乱)以前的代码(如果我删除了所有控件,但它有效):
function retrive_avaible_operator($Hostname, $Username, $Password, $DatabaseName, $SupportUserPerDepaTable, $SupportUserTable,$dep){
$query = "SELECT `user_id` FROM ".$SupportUserPerDepaTable." WHERE `department_id`=? AND `user_id`!=".$_SESSION['id'] ;
$mysqli = new mysqli($Hostname, $Username, $Password, $DatabaseName);
$stmt = $mysqli->stmt_init();
$prepared = $stmt->prepare($query);
$stmt->bind_param('i', $dep)
$stmt->execute()
$stmt->store_result();
$operator=array();
$result = $stmt->bind_result($camaro);
if($stmt->num_rows>0){
while (mysqli_stmt_fetch($stmt))
$operator[]=$camaro;
$operator=join(',',$operator);
$query = "SELECT `id` FROM ".$SupportUserTable." WHERE `id` IN (".$operator.") AND `holiday`='0' ORDER BY `assigned_tickets` ASC LIMIT 1" ;
$prepared = $stmt->prepare($query);
$prepared)
$stmt->execute()
$stmt->store_result();
$result = $stmt->bind_result($camaro);
if($stmt->num_rows>0){
while (mysqli_stmt_fetch($stmt))
$selopid=$camaro;
return $selopid;
}
else{
$query = "SELECT `id` FROM ".$SupportUserTable." WHERE `status`=2 AND `holiday`=0 AND `id`!=".$_SESSION['id']." ORDER BY `assigned_tickets` ASC, `solved_tickets` ASC LIMIT 1" ;
$prepared = $stmt->prepare($query);
$prepared
$stmt->execute()
$stmt->store_result();
$result = $stmt->bind_result($camaro);
if($stmt->num_rows>0){
while (mysqli_stmt_fetch($stmt))
$selopid=$camaro;
return $selopid;
}
else
return 'No Operator Available';
}
}
else{
$query = "SELECT `id` FROM ".$SupportUserTable." WHERE `status`='2' AND `holiday`='0' AND `id`!=".$_SESSION['id']." ORDER BY `assigned_tickets` ASC, `solved_tickets` ASC LIMIT 1" ;
$prepared = $stmt->prepare($query);
$stmt->execute()
$stmt->store_result();
$result = $stmt->bind_result($camaro);
if($stmt->num_rows>0){
while (mysqli_stmt_fetch($stmt))
$selopid=$camaro;
return $selopid;
}
else
return 'No Operator Available';
}
$mysqli->close();
}