it seem like i get stocked in loop ,i didn't know why this is my code-
$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";
}
}
}
}
}
It seems your "back" function calls "choose" function.
And your "choose" function calls your "back" function.
The loop is complete.
I have marked it with //////// to make it easy to find.
Edit I see now that there is several places in back you call choose. I have only marked one.
It's not to hard to find it with search function of any developer app.
$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";
}
}
}
}
}
Related
I submitted these two files:
sample_annotation.txt
sample_synteny.txt
I got on the next page the following error:
304501820180500000018.304501820180500000018<br><br>select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny<br><br>
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.304501820180500000018.'_synteny union select distinct org1,org2 from '.3045018' at line 1
Whole query: select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny[]
The mGSV/lib/data.php looks like below and caused the above error:
<?php
include('database.php');
## Get parameters
$org = $_GET['org'];
$data = $_GET['data'];
$session_id = $_GET['session_id'];
$array = array();
if($data == 'annotation') {
$query = "SELECT track_name FROM ".$session_id."_annotation WHERE org_id like '$org' GROUP BY track_name ";
$result = mysql_query($query);
if($result != ''){
while($row = mysql_fetch_assoc($result)){
array_push($array, $row['track_name']);
}
}
//array_push($syn_array, "10_50_20_70");
}
else if ($data == 'synteny') {
$query = "DESC ".$session_id."_synteny";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
if($row['Field'] == 'id'){ continue; }
if($row['Field'] == 'blocks'){ continue; }
if($row['Field'] == 'SYNcolor'){ continue; }
if(! preg_match("/^org[12]+[_]?[start|end]?/", $row['Field'])){
array_push($array, $row['Field']);
}
}
}
else if ($data == 'size'){
echo "$session_id.", $session_id, "<br>";
echo "$org", $org, "<br>";
$query = "select distinct org1,org2 from '.$session_id.'_synteny union select distinct org1,org2 from '.$session_id.'_synteny";
echo $query,"<br>";
$result = mysql_query($query);
echo $results,"<br>";
if ($results) {
while($row = mysql_fetch_assoc($result)){
echo $row['org1'], "<br>";
$q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org1'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org1'] . "') as t1";
echo $q, "<br>";
$res = mysql_query($q);
if (!$res) {
die('Could not query:' . mysql_error());
}
echo $row['org1'],"<br>";
echo $row['org2'],"<br>";
if (! isset($array[$row['org1']])){
//echo "add<br>";
$array[$row['org1']] = mysql_result($res,0);
}
$q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org2'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org2'] . "') as t1";
#echo $q, "<br>";
$res = mysql_query($q);
if (!$res) {
die('Could not query:' . mysql_error());
}
if (! isset($array[$row['org2']])){
//echo "add<br>";
$array[$row['org2']] = mysql_result($res,0);
}
}
}
else {
echo 'Invalid query: ' . mysql_error() . "\n";
echo 'Whole query: ' . $query;
}
}
else if ($data == 'order'){
$query = "select distinct org1 from ".$session_id."_synteny union select distinct org2 from ".$session_id."_synteny ";
//echo $query,"<br>";
$result = mysql_query($query);
$default = array();
while($row = mysql_fetch_assoc($result)){
array_push($default, $row['org1']);
}
$array = join('__ORDER__', $default);
}
else if ($data == 'sorder'){
$query = "select distinct org1,org2 from ".$session_id."_synteny union select distinct org1,org2 from ".$session_id."_synteny ";
//echo $query,"<br>";
$result = mysql_query($query);
$default = array();
$assarr = array();
while($row = mysql_fetch_assoc($result)){
if( ! in_array($row['org1'], $default)){
array_push($default, $row['org1']);
$assarr[sizeof($assarr)] = array();
}
if( ! in_array($row['org2'], $default)){
array_push($default, $row['org2']);
$assarr[sizeof($assarr)] = array();
}
$len_query = "select sum(org1_end) - sum(org1_start) + sum(org2_end) - sum(org1_start) as sum from ".$session_id."_synteny where (org1 like '".$row['org1']."' and org2 like '".$row['org2']."') OR (org1 like '".$row['org2']."' and org2 like '".$row['org1']."')";
$q_result = mysql_query($len_query);
$q_row = mysql_fetch_assoc($q_result);
#echo $len_query,"<br>";
#echo $q_row['sum'],"<br>";
$assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = $q_row['sum'];
#$assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = 1;
$assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = $q_row['sum'];
#$assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = 1;
#echo array_search($row['org1'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
$assarr[array_search($row['org1'], $default)][array_search($row['org1'], $default)] = 0;
#echo array_search($row['org1'], $default) . "][ ". array_search($row['org1'], $default) . '<br>';
$assarr[array_search($row['org2'], $default)][array_search($row['org2'], $default)] = 0;
#echo array_search($row['org2'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
}
$a = FindOrder($assarr);
$sugg = array();
//echo sizeof($a),'<br>';
foreach($a as $b){
//echo $default[$b],"<br>";
array_push($sugg, $default[$b]);
}
$array = join('__ORDER__', $sugg);
}
function FindOrder($graph){
$r = array();
$last = -1;
while(!isEmpty($graph)){
$start = leastEdges($graph);
$path = longestPath($graph, $start, 0);
$path = completeCycle($graph, $path);
if($path[0] != $last){
array_push($r, $path[0]);
}
for($x = 1; $x < sizeof($path); $x++){
array_push($r, $path[$x]);
}
$last = $path[sizeof($path)-1];
$graph = removePath($graph, $path);
}
return $r;
}
function longestPath($graph, $cur, $len){
$path = array();
array_push($path, $cur);
$longestSubpath = array();
for($x = 0; $x < sizeof($graph); $x++){
if($graph[$cur][$x] != 0){
$subpath = longestPath(removeVertex($graph, $cur), $x, $len + $graph[$cur][$x]);
if(sizeof($subpath) > sizeof($longestSubpath)){
$longestSubpath = $subpath;
}
}
}
foreach($longestSubpath as $x){
array_push($path, $x);
}
return $path;
}
function completeCycle($graph, $path){
$graph = removePath($graph, $path);
$last = $path[sizeof($path)-1];
for($x = 0; $x < sizeof($graph); $x++){
if($graph[$last][$x] != 0){
array_push($path, $x);
return $path;
}
}
return $path;
}
function removePath($graph, $path){
for($x = 0; $x < sizeof($path) - 1; $x++){
$arr = $path[$x]; //***forgot the $ in front of path***
$b = $path[$x+1]; //***forgot the $ in front of path***
$graph[$arr][$b] = 0;
$graph[$b][$arr] = 0;
}
return $graph;
}
function removeVertex($graph, $vtx){
if($vtx < 0 || $vtx >= sizeof($graph)){
return copy($graph);
}
for($x = 0; $x < sizeof($graph); $x++){
$graph[$x][$vtx] = 0;
$graph[$vtx][$x] = 0;
}
return $graph;
}
function numEdges($vtx){
$r = 0;
foreach($vtx as $x){
if($x != 0){
$r++;
}
}
return $r;
}
function leastEdges($graph){
$r = -1;
$min = 2147483647;
for($x = 0; $x < sizeof($graph); $x++){
$e = numEdges($graph[$x]);
if($e != 0 && $e < $min){
$r = $x;
$min = $e;
}
}
return $r;
}
function isEmpty($arr){
$r = true;
foreach($arr as $x){
$r = $r && numEdges($x) == 0;
}
return $r;
}
## Return the JSON object
echo json_encode($array);
?>
I created a docker-compose.yml and the can be run in the following way:
git clone https://github.com/mictadlo/mGSV-docker.git
docker-compose up --build
The service can be accessed via localhost and PhpMyAdmin can be accessed via localhost:8183
What did I miss?
Thank you in advance
Try to run independently both query in your Mysql phpmyadmin
select distinct org1,org2 from '.304342020180200000016.'_synteny
select distinct org1,org2 from '.304342020180200000016.'_synteny
As i see your query seems to be correct since union requires the same numbers of columns and same data type.
And why is your table name in the union query is both the same.
need some helps here: i try to import some excel sheets to my website, but the page keep loading and then stop working and showing internal server error text. the error log shows this caused by the import.php :Premature end of script headers: php-cgi, referer: ...file_import.php.
below are the codes:
<? include("../include/begin.inc.php");?>
<?
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
function sava_data($array, $table){
$count = 0;
$total = 0;
foreach( $array as $tmp){
if ($count <> 0){
$date = date("Y:m:d H:i:s");
$sql = "INSERT INTO $table set ";
$sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
//echo $sql."<br>";
//exit();
if (!($result = #mysql_query($sql) or die("Error:" . mysql_error().$sql)))
showerror();
$total++;
}
$count++;
}
return $total;
}
function save_data2($array,$table){
$count = 0;
$total = 0;
foreach( $array as $tmp){
if ($count <> 0){
$date = date("Y:m:d H:i:s");
$sql = "INSERT INTO $table set ";
$sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
//echo $sql."<br>";
//exit();
if (!($result = #mysql_query($sql) or die("Error:" . mysql_error().$sql)))
showerror();
$total++;
}
$count++;
}
return $total;
}
function empty_data($table){
if($table == "fancy_table"){
$s3 = "select * from $table where file != ''";
$r3 = mysql_query($s3);
while($d3 = mysql_fetch_array($r3)){
$del_lo_l="../../_files/fancy_product/".$d3['file'];
if(file_exists($del_lo_l))
{
#unlink($del_lo_l);
}
}
}
$s4 = "truncate table `$table`";
mysql_query($s4);
$s5 = "OPTIMIZE TABLE `$table`";
mysql_query($s5);
}
//error_reporting(E_ALL ^ E_NOTICE);
$action = $_REQUEST['action'];
if($_POST){
if($action == "empty"){
empty_data("artwork");
}else if($action == "imported"){
$Import_TmpFile = $_FILES['file']['tmp_name'];
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($Import_TmpFile);
$total = 0;
//for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
for ($i = 4; $i <= 65536; $i++) {
if ($data->sheets[0]['cells'][$i][2] <> ""){
$sql = "INSERT INTO artwork set detail = '".$data->sheets[0]['cells'][$i][2]."', shape = '".$data->sheets[0]['cells'][$i][3]."', qty = '".$data->sheets[0]['cells'][$i][4]."', price = '".$data->sheets[0]['cells'][$i][5]."', percent = '".$data->sheets[0]['cells'][$i][6]."', colour = '".$data->sheets[0]['cells'][$i][7]."', clarity = '".$data->sheets[0]['cells'][$i][8]."', prop = '".$data->sheets[0]['cells'][$i][9]."', polish = '".$data->sheets[0]['cells'][$i][10]."', smy = '".$data->sheets[0]['cells'][$i][11]."', diam = '".$data->sheets[0]['cells'][$i][12]."', t_dep = '".$data->sheets[0]['cells'][$i][13]."', `table` = '".$data->sheets[0]['cells'][$i][14]."', fl = '".$data->sheets[0]['cells'][$i][15]."', colour_shade = '".$data->sheets[0]['cells'][$i][16]."', cert = '".$data->sheets[0]['cells'][$i][17]."', cert_no = '".$data->sheets[0]['cells'][$i][18]."', per_kg = '".$data->sheets[0]['cells'][$i][19]."', selling_price = '".$data->sheets[0]['cells'][$i][20]."', status = 'new', create_date = now()";
$result = #mysql_query($sql);
$total++;
}
}
echo $total;
//$total = sava_data($array, "artwork");
}else if($action == "fancy_imported"){
$Import_TmpFile = $_FILES['file']['tmp_name'];
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($Import_TmpFile);
$total = 0;
//for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
for ($i = 4; $i <= 65536; $i++) {
if ($data->sheets[0]['cells'][$i][2] <> ""){
$sql = "INSERT INTO fancy_style set detail = '".$data->sheets[0]['cells'][$i][2]."', artworktype = '".$data->sheets[0]['cells'][$i][3]."', shape = '".$data->sheets[0]['cells'][$i][4]."', qty = '".$data->sheets[0]['cells'][$i][5]."', colour = '".$data->sheets[0]['cells'][$i][6]."', cut = '".$data->sheets[0]['cells'][$i][7]."', measurements = '".$data->sheets[0]['cells'][$i][8]."', treatment = '".$data->sheets[0]['cells'][$i][9]."', origin = '".$data->sheets[0]['cells'][$i][10]."', comments = '".$data->sheets[0]['cells'][$i][11]."', cert = '".$data->sheets[0]['cells'][$i][12]."', cert_no = '".$data->sheets[0]['cells'][$i][13]."', `per_kg` = '".$data->sheets[0]['cells'][$i][14]."', status = 'new', create_date = now()";
$result = #mysql_query($sql);
$total++;
}
}
echo $total;
}else if($action == "fancy_empty"){
empty_data("fancy_style");
}
}
//exit();
jsRedirect(geturlname().".php?action=".$action."&rows=".$total);
?>
<? include("../include/end.inc.php");?>
Why I am getting 0 instead values from the database? What I am doing wrong if I give $_POST['dataType'] === 'start'. I never call a multiple DB select request. What I am doing wrong?
UPDATED:
if(isset($_POST['dataType'])){
switch ($_POST['dataType']) {
case 'start':
$data_type = 'pictures, videos, audio, documents';
break;
case 'picture':
$data_type = 'pictures';
break;
case 'video':
$data_type = 'videos';
break;
case 'audio':
$data_type = 'audio';
break;
case 'document':
$data_type = 'documents';
break;
default:
$data_type = '';
}
if (!empty($data_type)) {
$userId = mysqli_real_escape_string($connect, $_SESSION['userId']);
if ($_POST['dataType'] !== 'start')
$sql = "SELECT * FROM " . $data_type . " WHERE user_id = " . $userId;
else {
$sql_picture = "SELECT * FROM pictures WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_videos = "SELECT * FROM videos WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_audio = "SELECT * FROM audio WHERE user_id = " . $userId . " ORDER BY upload_time";
$sql_documents = "SELECT * FROM documents WHERE user_id = " . $userId . " ORDER BY upload_time";
}
// Check connection
if ($connect->connect_error) {
mysqli_close($connect);
echo 1;
}
else {
if ($_POST['dataType'] !== 'start'){
$result = $connect->query($sql);
if ($result->num_rows > 0) {
$indexOfSuggests = 0;
$data = array();
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$data[$indexOfSuggests] = array($id, $user_id, $name, $public, $link, $upload_time);
$indexOfSuggests++;
}
$result->free();
echo json_encode($data);
}
else {
echo 0; // keine ergebnisse
}
}
else {
$indexOfSuggests = 0;
$new_index;
$collectData = array();
for($i = 0; $i < 4; $i++){
$indexOfSuggests = $new_index;
if($i == 0)
$sql = $sql_picture;
else
if($i == 1)
$sql = $sql_videos;
else
if($i == 2)
$sql = $sql_audio;
else
if($i == 3)
$sql = $sql_documents;
$result = $connect->query($sql);
if ($result->num_rows > 0) {
$data = array();
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$data[$indexOfSuggests] = array($id, $user_id, $name, $public, $link, $upload_time);
array_push($collectData, $data[$indexOfSuggests]);
$indexOfSuggests++;
}
$new_index = $indexOfSuggests;
}
else {
// keine ergebnisse
}
}
echo json_encode($collectData);
}
}
}
else {
header("Location: http://google.com");
}
}
So i got it but in a really uncool way. So the last thing I have to do is to order the array values by date.
here is new fix :)
<?php
if (isset($_POST['dataType'])) {
switch ($_POST['dataType']) {
case 'start':
$data_type = 'pictures,videos,audio,documents';
break;
case 'picture':
$data_type = 'pictures';
break;
case 'videos':
$data_type = 'videos';
break;
case 'audio':
$data_type = 'audio';
break;
case 'documents':
$data_type = 'documents';
break;
default:
$data_type = '';
}
function get_list ($sql,&$list) {
// Create connection
$connect = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($connect->connect_error) {
die(1);
} else {
$result = $connect->query($sql);
while ($row = $result->fetch_assoc()) {
$id = $row['id'];
$user_id = $row['user_id'];
$name = $row['name'];
$public = $row['public'];
$link = $row['link'];
$upload_time = $row['upload_time'];
$list[] = array($id, $user_id, $name, $public, $link, $upload_time);
}
}
}
if (!empty($data_type)) {
$list = array();
$userId = mysqli_real_escape_string($_SESSION['userId']);
if ($_POST['dataType'] !== 'start') {
$sql = "SELECT * FROM " . $data_type . " WHERE user_id = " . $userId;
get_list($sql,$list);
} else {
$data_types = explode(',',$data_type);
foreach($data_types as $type) {
$sql = "SELECT * FROM " . $type . " WHERE user_id = " . $userId;
get_list($sql,$list);
}
}
if(empty($list))
die(0);
else
echo json_encode($list);
} else {
header("Location: http://google.com");
}
}
?>
As the title says, I cannot update the cart total amount. Here's the scenario of my situation.
I have a checkout page in which there is an option of shipping amount in which the user has to select an option from the drop down menu. Once chosen, the cart total amount should get updated adding the shipping charges in the header where my navigation links are and also in the page where I want the user to click the button for checking out.
Here's the shipping charge HTML code:
<select name="selectZone" id="custDelAddZone">
<option value="-1">----- Select -----</option>
<?php
$queryForZone = "SELECT * FROM shipping_zones ORDER BY ZoneName";
$validate->Query($queryForZone);
if ($validate->NumRows() >= 1) {
while ($row = $validate->FetchAllDatas()) {
echo '<option value="'.$row['ZoneId'].'">'.$row['ZoneName'].'</option>';
}
}
?>
</select>
<button name="CustDelAddUpdateZone" id="btnCustDelAddUpdateZone" type="submit">Continue</button>
Here's the AJAX part of the button click:
$("#btnCustDelAddUpdateZone").click(function() {
zoneId = $("#custDelAddZone").val();
if (zoneId == '-1') {
toastr.error("Please Select The Region", "Error");
toastr.options.showMethod = "slideDown";
toastr.options.hideMethod = "slideUp";
}
var dataStr = $("#chooseShippingZoneForm").serialize();
$.ajax({
url: 'http://localhost/ECommerceOnFlatastic/ActionFiles/Customers/UpdateDeliveryZone.php',
type: 'POST',
data: dataStr,
success: function(msg) {
toastr.success(msg);
toastr.options.showMethod = "slideDown";
toastr.options.hideMethod = "slideUp";
$("#selectZoneForm").slideUp();
$("#delMethod h3").removeClass("color_light active");
$("#paytMethod").show();
$("#paytMethod h3").removeClass("bg_light_color_1 color_dark");
$("#paytMethod h3").addClass("color_light active");
$("#payment").slideDown();
}
});
return false;
});
And here's the PHP script (UpdateDeliveryZone.php):
<?php
session_start();
$zoneId = $custCode = "";
require_once '../../Classes/class.Validation.php';
$validate = new Validation('developi_ecommerce');
$q = "SELECT CustCode FROM customers WHERE CustEmailAdd = '".$_SESSION['Customer']['email']."'";
$validate->Query($q);
if ($validate->NumRows() >= 1) {
while ($row = $validate->FetchAllDatas()) {
$custCode = $row['CustCode'];
}
} else {
echo "No Customer Found";
}
if ( isset( $_POST['selectZone'] ) && $_POST['selectZone'] != "" ) {
$zoneId = $validate->EscapeString( $_POST['selectZone'] );
$query = "UPDATE customers_delivery_address SET ZoneId = '".$zoneId."' WHERE CustCode = '".$custCode."' AND CustDelAddLastInserted >= NOW() - INTERVAL 10 MINUTE";
if ( $validate->Query( $query ) == TRUE ) {
echo "Updated Successfully";
} else {
echo "Invalid Query";
}
} else {
echo "Value Not Set";
}
?>
And here's how I am trying to get the cart total amount in PHP:
if ($validate->Query($sql) == TRUE) {
if ($validate->NumRows() >= 1) {
while ( $row = $validate->FetchAllDatas() ) {
echo '<tr>';
echo '<td style="width: 50%;" data-title="Product Image & name" class="t_md_align_c"><img src="images/Products/'.$row['ProdCode'].'.jpg" alt="'.$row['ProdCode'].'" class="m_md_bottom_5 d_xs_block d_xs_centered" height="75" width="75">'.$row['ProdName'].'</td>';
echo '<td style="width: 5%;" data-title="SKU">'.$row['ProdCode'].'</td>';
echo '<td style="width: 5%;" data-title="Price"><p class="f_size_large color_dark">Rs. '.$row['ProdRate'].'</p></td>';
echo '<td style="width: 5%;" data-title="Quantity"><div class="clearfix d_inline_middle f_size_medium color_dark m_bottom_10">'.$_SESSION['cart'][$row['ProdCode']]['quantity'].'</div></td>';
$sbTotal = $row['ProdRate'] * $_SESSION['cart'][$row['ProdCode']]['quantity'];
$subTotal = $sbTotal;
echo '<td style="width: 5%;" data-title="Subtotal"><p class="f_size_large fw_medium scheme_color t_align_r">'.number_format($sbTotal, 2).'</p></td>';
$total += $subTotal;
$_SESSION['cartTotalAmount'] = $total;
$tax = $row['CatTaxPercent'];
$taxAmt = (($sbTotal * $tax ) / 100);
$taxAmount += $taxAmt;
$amt = 0;
$cartWeightPerProduct = ($row['weight'] * $_SESSION['cart'][$row['ProdCode']]['quantity']);
echo '</tr>';
$totalCartWeight += $cartWeightPerProduct;
}
$totalTaxAmount += $taxAmount;
$_SESSION['cartWeight'] = $totalCartWeight;
$sessAmnt = ($total + $totalTaxAmount);
$totalPayableAmnt = $sessAmnt + $_SESSION['TotalWeight']; // This is my cart total amount
$_SESSION['sessionTotalPayable'] = number_format($totalPayableAmnt, 2);
if ( isset( $_SESSION['sessionTotalPayable'] ) ) {
$amt = $totalPayableAmnt;
} else {
$amt = "Rs. 0";
}
echo '<tr><td colspan="4"><p class="fw_medium f_size_large t_align_r t_xs_align_c">Cart Total:</p></td><td colspan="1"><p class="fw_medium f_size_large color_dark t_align_r">'.number_format($total, 2).'</p></td></tr>';
echo '<tr><td colspan="4"><p class="f_size_large t_align_r t_xs_align_c">Taxes:</p></td><td colspan="1"><p class="f_size_large color_dark t_align_r">'. number_format($totalTaxAmount, 2) .'</p></td></tr>';
echo '<tr><td colspan="4"><p class="f_size_large t_align_r t_xs_align_c">Shipping:</p></td><td colspan="1"><p id="shippingAmount" class="f_size_large color_dark t_align_r">'.number_format($_SESSION['TotalWeight'], 2).'</p></td></tr>';
echo '<tr><td colspan="4"><p class="fw_medium f_size_large t_align_r t_xs_align_c">Total Payable Amount:</p></td><td colspan="1"><p class="fw_medium f_size_large color_dark t_align_r">'.number_format($amt, 2).'</p></td></tr>';
}
}
For those who wants to know from where the $_SESSION['TotalWeight'] came from:
<?php
session_start();
require_once 'Classes/class.Validation.php';
function SelectZoneAmount($amt, $id) {
$validate = new Validation('developi_ecommerce');
$zoneCol = 0;
if ($amt >= 1 && $amt <= 499 ) {
$zoneCol = 'SWC_0_500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 500 && $amt <= 999) {
$zoneCol = 'SWC_500_1000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 1000 && $amt <= 1499) {
$zoneCol = 'SWC_1000_1500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 1500 && $amt <= 1999) {
$zoneCol = 'SWC_1500_2000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 2000 && $amt <= 2499) {
$zoneCol = 'SWC_2000_2500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 2500 && $amt <= 2999) {
$zoneCol = 'SWC_2500_3000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 3000 && $amt <= 3499) {
$zoneCol = 'SWC_3000_3500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 3500 && $amt <= 3999) {
$zoneCol = 'SWC_3500_4000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 4000 && $amt <= 4499) {
$zoneCol = 'SWC_4000_4500';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 4500 && $amt <= 4999) {
$zoneCol = 'SWC_4500_5000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
} elseif($amt >= 5000 && $amt <= 10000) {
$zoneCol = 'SWC_5000_10000';
$query = "SELECT $zoneCol FROM shipping_weight_charges WHERE ZoneId = '".$id."'";
$validate->Query($query);
while ($row = $validate->FetchAllDatas()) {
return $row[$zoneCol];
}
}
}
$region = 0;
if (isset($_POST['selectZone'])) {
$region = SelectZoneAmount($_SESSION['cartWeight'], $_POST['selectZone']);
$_SESSION['TotalWeight'] = $region;
echo number_format($_SESSION['TotalWeight'], 2);
}
?>
When I go to checkout page and select the shipping zone, I am not able to refresh the cart total amount. I know there must be a logical error somewhere. Kindly help me in rectifying the error.
Thank You in advance.
I think, error is found:
$_SESSION['sessionTotalPayable'] = number_format($totalPayableAmnt, 2);
you set value in session var by using number_format() function. this is wrong way.
you can use number_format() function only view section...
because, number_format() return a string . so, it can't calculate.
Please check your code based on above condition.
then that may solve.
I have a function in PHP that give me some values from DB
$select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");
if($select){
if(mysql_fetch_row($select) != 0){
$sep = "~";
$return = "";
$i = 0;
while($row = mysql_fetch_array($select)){
if($i > 0){
$return = $return.",";
};
$return = $return.$row['id'].$sep.$row['from_'];
$i += 1;
}
return $return;
}else{
return "NO";
}
}else{
return "E, 000, SELECT, ".mysql_error();
}
The problem is that if I do like in the code above it returns me nothing, instead, if I duplicate the select variable it works:
$select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");
$num_select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");
if($select){
if(mysql_fetch_row($num_select) != 0){
$sep = "~";
$return = "";
$i = 0;
while($row = mysql_fetch_array($select)){
if($i > 0){
$return = $return.",";
};
$return = $return.$row['id'].$sep.$row['from_'];
$i += 1;
}
return $return;
}else{
return "NO";
}
}else{
return "E, 000, SELECT, ".mysql_error();
}
Why ?
Instead of
mysql_fetch_row($select) != 0
use
mysql_num_rows($select) != 0
that will return an int for you to compare.