从Excel文件中,我如何获得特定国家/地区的最大速率,然后将其添加到MySQL数据库中


from excel file how i get max rate for a specific country and after that add it to the mysql db

<?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>

我有一个Excel文件,其中包含国家,运营商,费率,Prifix,MCCMNC。 在这里,它将具有每个国家/地区的多个国家和运营商以及费率。 我必须获取一个国家/地区的最大费率,然后将其添加到相同的运营商中,依此类推。

也许您可以先添加整个 excelfile,然后更轻松地制作一个 SQL 语句,将每个国家/地区的最高评级放入第二个数据库中?或者只是制作一个 forloop 来找到每个国家/地区的最高评级,然后删除较低的评级?

<?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>