Home Send results from one php program to another php program
Reply: 0

Send results from one php program to another php program

user4736
1#
user4736 Published in August 15, 2018, 9:02 am

I have a php program that reads excel file and returns the variable perfectly. The variable are as shown below

$str  = $jdate . ",";
$str .= $block . ",";
$str .= $a_harv . ",";
$str .= $b_harv . ",";
$str .= $loss . ",";
$str .= $sweet . ",";
$str .= $species . ",";
$str .= $comment . "\n";

Now I would to send these variable to another php program(the program sends the variables to data base, it also has no problem) to receive/get the variables as:

list($sdate,$block,$a_harv,$b_harv,$loss,$sweet,$species,$comment) = 
explode(",",$_GET['$str']);

I wonder how to connect these two programs?

The first is this readExcel_SendResult.php

<?php

date_default_timezone_set('Asia/Tokyo');


global $link, $db;

include('db.inc');

include_once( dirname( __FILE__ ) . '/PHPExcel-1.8/Classes/PHPExcel.php' );
include_once( dirname( __FILE__ ) . '/PHPExcel-1.8/Classes/PHPExcel/IOFactory.php' );


function endsWith( $str, $suffix ){
  $len = strlen( $suffix );
  return $len == 0 || substr( $str, strlen( $str ) - $len, $len ) === 
$suffix;
}

$excelfilename = 'harv.xlsx';
$excelfilepath = dirname( __FILE__ ) . '/' . $excelfilename;

$reader = null;
if( endsWith( $excelfilename, 'xls' ) ){
  $reader = PHPExcel_IOFactory::createReader( 'Excel5' );
}else if( endsWith( $excelfilename, 'xlsx' ) ){
  $reader = PHPExcel_IOFactory::createReader( 'Excel2007' );
}

if( $reader ){
  $excel = $reader->load( $excelfilepath );

  $obj1 = $excel->getActiveSheet()->toArray( null, true, true, true );
  $num_row = count($obj1);

  print "Variable Count:" . $num_row . "\n";
  for($i=0; $i<$num_row; $i++){
    $sdate = trim($obj1[$i]['A']);
    if($sdate == "")    continue;
    $block = str_replace(" ","",$obj1[$i]['B']);
    $block = mb_convert_kana($block,"r","utf-8");
    $a_harv = $obj1[$i]['C'];
    $b_harv = $obj1[$i]['D'];
    $loss = $obj1[$i]['E'];
    $sweet = trim($obj1[$i]['F']);
    $species = str_replace(" ","",$obj1[$i]['G']);
    $comment = trim($obj1[$i]['H']);

    list($mm, $dd, $yy) = explode("/",$sdate);
    if($yy == "")   continue;
    $jdate = $yy . "-" . $mm . "-" . $dd;

    $str  = $jdate . ",";
    $str .= $block . ",";
    $str .= $a_harv . ",";
    $str .= $b_harv . ",";
    $str .= $loss . ",";
    $str .= $sweet . ",";
    $str .= $species . ",";
    $str .= $comment . "\n";


    $shell .= "?ARG=" . $str;

  }
}else{
  echo "No reader.";
}
?>

The other program I have is this; send_datatoDB.php

global $link, $db;

include'excel_db.php'; 

include('db.inc');

list($sdate,$block,$a_harv,$b_harv,$loss,$sweet,$species,$comment) = 
explode(",",$_GET['$str']);

$block = mb_convert_kana($block,"r","utf-8");

if($species == "type1"){
    $vid = "v2";
} else if ($species == "type2"){
    $vid = "v3";
} else if ($species == "type3"){
    $vid = "v1";
} else {
    $vid = "v4";
}

if(is_numeric($sweet)){
    $sweetness = $sweet;
    $s_and_c = $comment;
} else {
    $sweetness = 0.0;
    $s_and_c = $sweet . $comment;
}


connect_mysql($link, $db);

    $sql = "Select * from tableName where sdate = '{$sdate}' and block = '{$block}' and vid = '{$vid}'";


    $result_id = mysqli_query($link,$sql);
    if($result_id == false){
        exit();
    }

    $row_cnt = mysqli_num_rows($result_id);
    echo "Result Number:" . $row_cnt . "<br>";

    while ($row = mysqli_fetch_assoc($result_id)) {
                $hid = $row['hid'];
                //echo "hid = " . $hid . "<br>";
    }

    mysqli_close($link);


connect_mysql($link, $db);

    if($row_cnt < 1){       //INSERT
        $values = "'{$sdate}' , '{$block}' , '{$vid}', '{$a_harv}', 
'{$b_harv}', '{$loss}', '{$sweetness}', '{$s_and_c}'";
        $sql = "INSERT into tableNamw ";
        $sql .= "(`sdate`, `block`, `vid`, `A_harv`, `B_harv`, `loss`, 
`sweetness`, `comments`) ";
        $sql .= " VALUES ({$values})";

    //echo $sql;

        $result_id = mysqli_query($link,$sql);
        if($result_id == false){
            exit();
        }
    } else {                        //UPDATE
        $sql = "UPDATE tableName SET ";
        $sql .= "a_harv = '" . $a_harv . "', ";
        $sql .= "b_harv = '" . $b_harv . "', ";
        $sql .= "loss = '" . $loss . "', ";
        $sql .= "sweetness = '" . $sweetness . "', ";
        $sql .= "comments = '" . $s_and_c . "'";
        $sql .= " where hid = " . $hid;

       //echo $sql . "<br>";

        $result_id = mysql_query($sql,$link);
        if($result_id == false){
            //echo "<BR>Uooops<BR>";

            exit();
        }
    }

mysqli_close($link);
?>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.267037 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO