<?php
@session_start();
include('checkstate.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read('case.xls');
error_reporting(E_ALL ^ E_NOTICE);

for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {   //取得excel的数据到一个数组realdata
	for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
		$item=getitem($data->sheets[0]['cells'],$i,$j);
	//	echo $item."<br>";
		$realdata[$i-1][$j-1]=$item;
	}
}

for($i=0;$i<count($realdata);$i++){
	$weburl=trim(str_replace("www.","",$realdata[$i][0]));
	$sql="select webId,comId from website where weburl like '".$weburl."' limit 0,1";
	$result=mysql_query($sql);
	if(mysql_num_rows($result)){
		$webid=mysql_result($result,0,'webId');
		$comid=mysql_result($result,0,'comId');
		$insert="insert into keyrank_temp(webid,keyword,transmean,searchid,rank,edittime) value($webid,'".$realdata[$i][2]."','".$realdata[$i][3]."','".$realdata[$i][1]."','".$realdata[$i][4]."','".date('Y-m-d')."' )";
		echo $insert;
		mysql_query($insert);
	}else{
		echo  $weburl."<br>";
	}
}





function getitem($arr,$k,$h){
	if($k==1){
		return $arr[$k][$h];
	}
	if(empty($arr[$k][$h])){
		return getitem($arr,$k-1,$h);
	}else{
		return $arr[$k][$h];
	}
}

?>
