関数の操作の数を 1 つのクエリだけに減らそうとしましたが、結果を取得できません。
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
どこからすべてのIDを選択しますa.department_id=?
$SupportUserTable
id が前の結果内にある場所からすべての 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;
編集
私は見つけました(残念ながら、beacuseは非常に醜くて面倒です)以前のコード(すべてのコントロールを削除しましたが、動作します):
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();
}