0
<?php


error_reporting(E_ALL ^ E_NOTICE);
//ini_set('display_errors', '1');

ini_set('max_execution_time',60);
$con=mysql_connect('localhost','root','');

$link=mysql_select_db('playsms');


if($_POST)
{


/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '/../../Classes/');

/** PHPExcel_IOFactory */
include('C:\xampp\htdocs\phpexcel\Classes\PHPExcel.php');
include('C:\xampp\htdocs\phpexcel\Classes\PHPExcel\IOFactory.php');
/** PHPExcel */
require_once 'C:\xampp\htdocs\phpexcel\Classes\PHPExcel.php';

/** PHPExcel_IOFactory */
require_once 'C:\xampp\htdocs\phpexcel\Classes\PHPExcel\IOFactory.php';
//include 'PHPExcel/IOFactory.php';
//create reader

//$inputFileName = $_GET['sel_file'];

 $file=$_FILES['sel_file']['name'];
                 if(!$file)
                 {
                 $file="";
                 }
     else
     {
                $target_path= "C:\\xampp\\htdocs\\playsms\\uploads\\";
                $target_path=$target_path.basename($_FILES['sel_file']['name']);

                if(move_uploaded_file($_FILES['sel_file']['tmp_name'],$target_path))
                {
                     echo "The file ".  basename( $_FILES['sel_file']['name']). 
                     " has been uploaded";
                }
                else
                {
                  echo "There was an error uploading the file, please try again!";
                }
    }           
//$inputFileName = "C:\Users\SHIVA\Desktop\CM.2012.25.xls";


$inputFileName= $target_path;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);

//$objPHPExcel = $objReader->load($inputFileName);

//echo 'File ',pathinfo($inputFileName,PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';

//echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

$objPHPExcel = $objReader->load($inputFileName);



$sheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
//var_dump($sheet);
//print_r($sheet);die;
$objsheet = $objPHPExcel->getActiveSheet();
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$nrColumns = ord($highestColumn) - 64;

echo "<br>File ".$sheetTitle  . " has ";
echo $nrColumns . ' columns';
echo $highestRow . ' rows.';

//  Loop through each row of the sheetData in turn    

    for ($row = 6; $row <= $highestRow; ++ $row)
     {  //echo "1"."\n" ;
            //$myvar=max;

        //for($i = 0; $i<=$highestRow; $i++)
        // echo "2"."\n" ;

        $val=array("i");


                for ($col = 0; $col <= $highestColumnIndex; ++ $col)
                 {
                    $cell = $sheet->getCellByColumnAndRow($col, $row);
                    $val[] = $cell->getValue();
                    echo $cell->getvalue(); 

                    //echo"<br>";

                }   
         //echo "<br><br><br>";
         //echo $val[2];
          //echo "<br><br><br>";
          $data=0;


          //$data = array();
            //$data[]=array($val2);  
          for($i = 0; $i<$highestRow; $i++)
           {
             //for($j=0;$j<$col; $j++)
            // {
            if( $data <= $val[6])
            {

                $data=$val[6];
                //mysql_query("SELECT max(rate) FROM `playsms_toolssimplerate` WHERE prefix=$val[12]");

                    //$data=$val[6];
                //echo "<br><br><br>";
                //$abc=$val[12];
                //$query =mysql_query("SELECT max(rate) as rate FROM `playsms_toolssimplerate` WHERE prefix='$abc'");
                 //$query['rate'];

                 //$result=mysql_query($query);
                // echo $query;
                //$data=$result;
            }   
            //}  
          }
          //echo $data; 
            //  echo "<br><br><br>";
         // echo $val[12];
          //extract($val);

        //print_r(array_values($val));
        //exit;
        //echo "</br></br></br></br>";
        $sql = "INSERT INTO playsms_toolssimplerate (dst,rate,mccmnc,prefix)
VALUES ('$val[2]- $val[4]','$data','$val[11]','$val[12]')";
//echo $sql."\n";
mysql_query($sql);
}
exit;
  }
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<br />
<br />
<br />
<br />
<br />

     <form action="" method="post" enctype="multipart/form-data" >

     <table border="1" width="40%" align="center">
<tr >
<td colspan="2" align="center"><strong>Import Excel file</strong></td>
</tr>

<tr>
<td align="center">Excel File:</td>
<td><input type="file" name="sel_file" id="sel_file" value=upload file/></td>
</tr>
<tr >
<td colspan="2" align="center"><input type="submit" name="submit" id="button" value="Submit" /></td>
</tr>
</table>

</form>
</table>
    <label></label></td>
  </tr>
</table> If The Table Is Filled Then Delete This<br />
<a href="javascript:linkto('index.php?app=menu&inc=tools_simplerate&op=simplerate_upload')"><h><input type='submit' class='button' value='DELETE TABLE'></h3></a>
<br />
<br />
</body>
</html>

国、オペレーター、レート、prifix、mccmncを含むExcelファイルがあります。これには、国ごとに複数の国とオペレーターがあり、料金もかかります。ある国の最大レートを取得してから、同じオペレーターに追加する必要があります。

4

2 に答える 2

0

たぶん、最初にExcelファイル全体を追加してから、2番目のデータベースに各国の最高評価を入れるSQLステートメントをより簡単に作成できますか? または、各国の最高の評価を見つけて、低い評価を削除する forloop を作成するだけですか?

于 2012-07-26T11:22:03.240 に答える
0
<?php


error_reporting(E_ALL ^ E_NOTICE);
//ini_set('display_errors', '1');

ini_set('max_execution_time',60);
$con=mysql_connect('localhost','root','');

$link=mysql_select_db('playsms');


if($_POST)
{


/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '/../../Classes/');

/** PHPExcel_IOFactory */
include('C:\xampp\htdocs\phpexcel\Classes\PHPExcel.php');
include('C:\xampp\htdocs\phpexcel\Classes\PHPExcel\IOFactory.php');
/** PHPExcel */
require_once 'C:\xampp\htdocs\phpexcel\Classes\PHPExcel.php';

/** PHPExcel_IOFactory */
require_once 'C:\xampp\htdocs\phpexcel\Classes\PHPExcel\IOFactory.php';
//include 'PHPExcel/IOFactory.php';
//create reader

//$inputFileName = $_GET['sel_file'];

 $file=$_FILES['sel_file']['name'];
                 if(!$file)
                 {
                 $file="";
                 }
     else
     {
                $target_path= "C:\\xampp\\htdocs\\playsms\\uploads\\";
                $target_path=$target_path.basename($_FILES['sel_file']['name']);

                if(move_uploaded_file($_FILES['sel_file']['tmp_name'],$target_path))
                {
                     echo "The file ".  basename( $_FILES['sel_file']['name']). 
                     " has been uploaded";
                }
                else
                {
                  echo "There was an error uploading the file, please try again!";
                }
    }           
//$inputFileName = "C:\Users\SHIVA\Desktop\CM.2012.25.xls";


$inputFileName= $target_path;
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);

//$objPHPExcel = $objReader->load($inputFileName);

//echo 'File ',pathinfo($inputFileName,PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';

//echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
$objReader = PHPExcel_IOFactory::createReader($inputFileType);

$objPHPExcel = $objReader->load($inputFileName);

$sheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
//var_dump($sheet);
//print_r($sheet);die;
$objsheet = $objPHPExcel->getActiveSheet();
$sheet = $objPHPExcel->getSheet(0); 
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$nrColumns = ord($highestColumn) - 64;

echo "<br>File ".$sheetTitle  . " has ";
echo $nrColumns . ' columns';
echo $highestRow . ' rows.';

//  Loop through each row of the sheetData in turn    

    for ($row = 6; $row <= $highestRow; ++ $row)
     {

        $val=array("i");


                for ($col = 0; $col <= $highestColumnIndex; ++ $col)
                 {
                    $cell = $sheet->getCellByColumnAndRow($col, $row);
                    $val[] = $cell->getValue();

                    //echo $cell->getvalue();   

                    //echo"<br>";

                }   


        $sql = "INSERT INTO playsms_toolssimplerate (dst,rate,prefix)
VALUES ('$val[2]- $val[4]','$val[6]','$val[12]')";
//echo $sql."\n";
mysql_query($sql);
}
 $sql="select distinct prefix from playsms_toolssimplerate";
$query=mysql_query($sql);
//echo $query;
while($row=mysql_fetch_array($query))
{
$prefix_db=$row['prefix'];
$sql_max_rate="select max(rate) as maxrate from playsms_toolssimplerate where prefix='$prefix_db'";
$query_max_rate=mysql_query($sql_max_rate);
//echo $query_max_rate;
$row_max_rate_arr=mysql_fetch_array($query_max_rate);
$row_max_rate_val=$row_max_rate_arr['maxrate'];
echo $row_max_rate_val;
$sql_update="update playsms_toolssimplerate set rate='$row_max_rate_val' where prefix='$prefix_db'";
mysql_query($sql_update);

}

exit;
  }
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<br />
<br />
<br />
<br />
<br />

     <form action="" method="post" enctype="multipart/form-data" >

     <table border="1" width="40%" align="center">
<tr >
<td colspan="2" align="center"><strong>Import Excel file</strong></td>
</tr>

<tr>
<td align="center">Excel File:</td>
<td><input type="file" name="sel_file" id="sel_file" value=upload file/></td>
</tr>
<tr >
<td colspan="2" align="center"><input type="submit" name="submit" id="button" value="Submit" /></td>
</tr>
</table>

</form>
</table>
    <label></label></td>
  </tr>
</table> If The Table Is Filled Then Delete This<br />
<a href="javascript:linkto('index.php?app=menu&inc=tools_simplerate&op=simplerate_upload')"><h><input type='submit' class='button' value='DELETE TABLE'></h3></a>
<br />
<br />
</body>
</html>
于 2012-07-29T08:25:36.603 に答える