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");?>
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.
I have two tables i am using two quires to fetch data from them separately.
$query = mysql_query("SELECT * FROM offers");
$query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());
I am printing the result on one html-table.
.... the problem is that i want to know that why the loop is running for 11 times both.
1). I am using two while loops. 2). each loop is running for row->mysql_fetch_object times. please help me to find error why my both loops are running for 11 times. total 22 rows are present in html table output. but my both table have so many rows. 100 of rows in both table.
please check the code.
$query = mysql_query("SELECT * FROM offers");
$query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());
$x = 1;
$n = 0;
while($row = mysql_fetch_object($query))
{
$oid = $row->id;
$name = stripslashes($row->name);
$reward = stripslashes($row->credits);
$network = stripslashes($row->network);
$hits = $row->hits; //clicks; $epc = $row->epc;
$campid = stripslashes($row->campaign_id);
$country = $row->countries;
$url2=$row->link;
$desc=$row->description;
if($x%2 == 0)
{
$trColor = "f1f0f0";
}else
{
$trColor = "ffffff";
}
if(stristr($country, ","))
{
$country_arrs = explode(",", $country);
$country = implode(", ", $country_arrs);
}
?>
<tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value="<?=$oid?>" name="ids[]" onclick="uncheckCheckAllbox(this)" /></td><td><?=$campid?>- campId</td><td><?=$name?></td><td><?=$reward?><td><?=$network?><td><?=$desc?></td><td>Click Here</td></td><td><?=$country?></td></tr>
$n++;
while($row1 = mysql_fetch_object($query1))
{
$uuid = $row1->offers_uuid;
$title1 = stripslashes($row1->title);
$info1 = stripslashes($row1->info_short);
$device_kind1 = stripslashes($row1->device_kinds);
$country1 = stripslashes($row1->target_groups_values);
// $status = toggleStatus($row->active);
$reward_dollar1 = $row1->reward_dollar; //clicks;
$url1 = $row1->url;
$network1 = 'Dalia';
$url1 = urldecode($url1);
if($x%2 == 0)
{
$trColor = "f1f0f0";
}else
{
$trColor = "ffffff";
}
if(stristr($country, ","))
{
$country_arrs = explode(",", $country);
$country = implode(", ", $country_arrs);
}
?>
<tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value="" onclick="uncheckCheckAllbox(this)" /></td><td><?=$uuid?></td><td><?=$title1?></td><td><?=$reward_dollar1?></td><td><?=$network1?></td><td><?=$info1?></td><td>Click Here</td><td><?=$country1?></td></tr>
$n++;
$x++;
goto n;
}
n:
$x++;
}
With my code below i have array item with multiple record i which to update each record into database with one query but only the last item of each array record was updated here is my code
:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
?>
i appliciate your impact
Try this:
<?php
require("init.php");
$sql = "SELECT item_name, quantity
FROM books WHERE book = 1644445";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query))
{
$da = $row["item_name"];
$qty = $row["quantity"];
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code = '$da' LIMIT 1");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while ($row = mysqli_fetch_array($sql))
{
$id = $row["id"];
$type = $row["name"];
$code = $row["recharge"];
}
$set="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$coe=substr(str_shuffle($set), 0, 12);
if(preg_match('/(65265)/i', $type))
$type = "20";
if(preg_match('/(562546)/i', $type))
$type = "13";
if(preg_match('/(MTN)/i', $type))
$type = "12";
if(preg_match('/(56556)/i', $type))
$type = "16";
$disp = str_split($code, $type);
for($b = 0; $b<$qty; $b++){
$pin = "$disp[$b]";
$gam = array(0 => array("post" => $pin));
foreach($gam as $gg)
{
$pp = $gg["post"];
$go = mysqli_query($conn, "UPDATE promo SET recharge='$coe$pp' WHERE id=$id");
if($go)
{
echo "<br/> $pp";
echo "<br/> $coe";
}
}
}
}
}
?>
The update is only executed if $productCount > 0.
I have this question about SQL queries.
Here its is:
$allowed = array("Amsterdam", "Arnhem", "Assen", "Groningen", "Leeuwarden", "Rotterdam", "Sittard", "Tilburg", "Utrecht");
$filter = $db->prepare("SELECT * FROM users WHERE '$allowed' = '1'");
$filter->execute;
foreach($filter->fetchAll(PDO::FETCH_OBJ) as $filtered):
$amsterdam = $filtered->amsterdam;
$arnhem = $filtered->arnhem;
$assen = $filtered->assen;
$groningen = $filtered->groningen;
$leeuwarden = $filtered->leeuwarden;
$rotterdam = $filtered->rotterdam;
$sittard = $filtered->sittard;
$utrecht = $filtered->utrecht;
endforeach;
The output (when echoed) is blank.
How can I get the query to look for column names from the array?
All help is appreciated.
This did it for me:
$query = $db->prepare("SELECT * FROM tbl_users WHERE id = '{$userId}'");
$query->execute();
foreach($query->fetchAll(PDO::FETCH_OBJ) as $value){
$districts = array("amsterdam","arnhem","assen","groningen","leeuwarden","rotterdam","sittard","tilburg","utrecht","antillen","missie","dap","sap");
$arrlength = count($districts);
for($x = 0; $x < $arrlength; $x++) {
if($value->$districts[$x] == TRUE){
echo '<pre>';
echo ucfirst($districts[$x]) . ' --> ' . $value->$districts[$x];
echo '</pre>';
}
}
}
I have a table as shown below
The output from said table
Green, is where a winner has been announced, whereas yellow means they have submitted a report, but a winner hasn't been decided yet. (winner field not populated)
$roundBound = Array();
$query = "SELECT MIN(id), MAX(id) FROM $tablename GROUP BY round";
if($result = $Login->mysqli->query($query)) {
while ($row = $result->fetch_row()) {
$roundBound[] = $row[0];
$roundBound[] = $row[1];
}
}
for($i = 0; $i < count($roundBound); $i = $i + 2) {
$match = 0;
for($j = $roundBound[$i]; $j < $roundBound[$i + 1]; $j = $j + 2) {
$id1 = $j;
$id2 = $j+1;
$query = "SELECT t1.winner, t2.winner FROM $tablename as t1, $tablename as t2 WHERE t1.id=$id1 AND t2.id=$id2";
$result = $Login->mysqli->query($query);
$row = $result->fetch_row();
$win1 = $row[0];
$win2 = $row[1];
if (isset($win1) && isset($win2)) {
if (isset($roundBound[$i + 2])) {
$id = $roundBound[$i + 2] + $match;
$query = "UPDATE $tablename SET
username = '$win1',
username2 = '$win2'
WHERE id = $id";
$Login->mysqli->query($query);
} else {
//Tourneydonneee yeeee
}
}
$match++;
}
}
Does anyone have a improvement, or an all-around different idea? This will be running quite often and could be potentially running on large record sets, so optimization would also be welcome.
as far as i understand you problem, i can suggest you to try
for ($i = 0; $i < count($arr); $i = $i + 2) {
$win1 = mysql_query("SELECT winner FROM tableName WHERE id=".(int)$i);
$win2 = mysql_query("SELECT winner FROM tableName WHERE id=".(int)$i+1);
$qry = "INSERT INTO tableName SET
username = $win1,
username2 =$win2,
....";
mysql_query($qry);
}