好像我在循环中放养,我不知道为什么这是我的代码 -
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}
答案 0 :(得分:0)
您的“后退”功能似乎称为“选择”功能 您的“选择”功能会调用您的“后退”功能 循环完成。
我已将其标记为////////
,以便于查找
编辑我现在看到后面有几个地方叫你选择。我只标记了一个
使用任何开发者应用程序的搜索功能都不难找到它。
$db = new mysqli("localhost", "root", "", "gdwal");
$sub = mysqli_query($db, "SELECT *,priority FROM subjects,teacher WHERE teach =techID ");
$stack = array();
$num = mysqli_query($db, "SELECT count(capacity)'h' FROM rooms ");
$table[][] = array();
$x = mysqli_fetch_array($num);
$table[0][0] = 0;
if ($db) {
echo 'connected';
}
/* function seet()
{
global $db;
$a=mysqli_query($db,"SELECT * from options ");
while ($row = mysqli_fetch_array($a)) {$z=$row['choices'];
echo($z);
$e=mysqli_query($db,"SELECT * from timeslot where sname=$z ");
$y=mysqli_fetch_array($e);
$x=$y['sindex'];
echo"//////$x/////+";
$b=mysqli_query($db,"UPDATE options SET `choices`=$x WHERE choices=$z ");
if($db->query($b)===true)
{
echo "lk";
}
}
}
seet(); */
for ($u = 0; $u <= 70; $u++) {
for ($g = 0; $g < 10; $g++) {
$table[$u][$g] = 0;
}
}
choose();
function choose() {
$sum = 0;
$sums = 0;
$best = array();
$prev = 0;
$best[0] = 0;
$best[1] = 0;
$best[2] = 100;
$best[3] = 0;
$best[4] = 0;
global $sub;
global $table;
global $stack;
global $db;
$ee = mysqli_query($db, "SELECT a.cid,c.NOstd,t.priority,c.hours,a.choices ,class,c.teacher_id FROM options a LEFT JOIN subjects c ON c.subject_id = a.cid LEFT JOIN teachers t ON t.id = c.teacher_id ");
while ($row = mysqli_fetch_array($ee)) {
if (!in_array($row['cid'], $stack)) {
$r = $row['cid'];
echo "$r-----";
$new = $r;
if ($prev===$new) {
} else {
$sum = 0;
$prev =$new;
}
$z = mysqli_query($db, "SELECT ind FROM rooms where capacity>='$r'");
while ($j = mysqli_fetch_array($z)) {
$hh = $row['choices'];
$uu = $j['ind'];
if ($table[$hh][$uu] == 0) {
$sum++;
}
}
if ($sum == 0) {
break;
}
$sums = $sum;
if ($best[2] == $sum && $best[3] < $row['priority']) {
echo $row['cid'];
echo '09090909090909';
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
} else {
if ($best[2] > $sum) {
$best[0] = $row['cid'];
$best[1] = $row['NOstd'];
$best[2] = $sums;
$best[3] = $row['priority'];
$best[4] = $row['teacher_id'];
$best[5] = $row['hours'];
$best[6] = $row['class'];
}
}
}
}
/////////////////
/////////////////
/////////////////
back($best);
}
function back($courses) {
global $stack;
global $db;
global $table;
$y =$courses[0];
$i = 0;
global$x;
$numsub = mysqli_query($db, "SELECT COUNT(DISTINCT cid)'jj' FROM options ");
$nn = mysqli_fetch_array($numsub);
$t = 0;
echo "XXX";
echo "//$y//";
echo "SELECT * FROM options WHERE cid='$y'";
echo "XXX";
$slot = mysqli_query($db, "SELECT * FROM options WHERE cid='$y'");
while ($rows = mysqli_fetch_array($slot)) {
$rom = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
$j = mysqli_query($db, "SELECT * FROM rooms where capacity>='$courses[1]'");
while ($D = mysqli_fetch_array($rom)) {
if ($courses[5] == 3) {
echo "22";
if ($table[$rows['choices']][$D['ind']] != 0 && $table[($rows['choices'] + 1)][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
}
}
} else
if ($table[$rows['choices']][$D['ind']] != 0) {
$z = $table[$rows['choices']][$D['ind']];
$ff = mysqli_query($db, "SELECT teacher FROM subjects where course_id=$z ");
$selec = mysqli_fetch_array($ff);
$b = mysqli_query($db, "SELECT COUNT(`class`)'kk'FROM `subjects` WHERE `class` IN(SELECT `class` FROM subjects WHERE `course_id`=$z ) AND( course_id =$y OR`ssubject`=$y");
$count = mysqli_fetch_array($b);
if ($count['kk'] != 0 || $selec['teacher'] == $courses[4]) {
$t++;
if ($t != 0) {
break;
}
}
echo "1";
}
if ($t != 0) {
break;
}
}
while ($colmn = mysqli_fetch_array($j)) {
if ($courses[5] == 3) {
echo "uuuuuu";
$w = $table[$rows['choices']][$colmn['ind']];
$y = mysqli_query($db, "SELECT hours FROM subjects where course_id='$w' ");
$op = mysqli_fetch_array($y);
if ($op['hours'] == 3) {
$i = $table[($rows['choices'] - 1)][$colmn['ind']];
$q = mysqli_query($db, "SELECT hours ,course_id , FROM subjects WHERE course_id=$i");
$opi = mysqli_fetch_array($q);
if ($opi['hours'] == 3 && $opi['course_id'] == $w) {
array_push($stack, $courses[0]);
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[($rows['choices']) + 1][$colmn['ind']] = 0;
array_pop($stack);
}
} elseif ($table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
$table[($rows['choices'] + 1)][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
$table[($rows['choices'] + 1)][$colmn['ind']] = 0;
array_pop($stack);
}
//end of t
}//end of courses 3
else {
if ($t == 0 && $table[$rows['choices']][$colmn['ind']] == 0) {
array_push($stack, $courses[0]);
$table[$rows['choices']][$colmn['ind']] = $courses[0];
if (count($stack) == $nn['jj']) {
database($table);
break;
}
///////////////////////
///////////////////////
///////////////////////
choose();
$table[$rows['choices']][$colmn['ind']] = 0;
array_pop($stack);
}
}
}
}
}
global $sub;
function database($tab) { // print_r($tab);
global $db;
$g = mysqli_query($db, "SELECT * FROM timeslot");
$r = mysqli_query($db, "SELECT * FROM rooms");
while ($ro = mysqli_fetch_array($g)) {
while ($co = mysqli_fetch_array($r)) {
if ($tab[$ro['sindex']][$co['ind']] === 0) {
} else {
echo 'iam in 2';
$x = $tab[$ro['sindex']][$co['ind']];
$u = mysqli_query($db, "select subject_id,hours,teacher_id,class from subjects WHERE subject_id='$x'");
$cor = mysqli_fetch_array($u);
$na = $cor['subject_id'];
$ho = $cor['hours'];
$tea = $cor['teacher_id'];
$clas = $cor['class'];
$tim = $ro['sindex'];
$km = $co['ind'];
$rmm = mysqli_query($db, "SELECT name FROM rooms where ind=$km");
$rom = mysqli_fetch_array($rmm);
$romm = $rom['name'];
$n = mysqli_query($db, "INSERT INTO ttable(name, teacher,class, timeslot, room, hours) VALUES ($na,$tea,$clas,$tim,$romm,$ho)");
$t = "INSERT INTO ttable(name, teacher, timeslot, room, hours) VALUES ('$na','$tea','$tim','$romm','$ho')";
echo "uuututyttuy";
if ($db->query($t) === true) {
echo "lklklklklklklklkl";
}
}
}
}
}