Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function curl($url, $post=''){
- $con=mysqli_connect("localhost","maruerti_vehicleprice","vehicleprice123","maruerti_vehicleprice");
- // Check connection
- if(mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- else{
- //echo "connected";
- }
- $_SESSION['price']='';
- $_SESSION['insurance']='';
- $_SESSION['rto']='';
- //cURL options
- $options = array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_HEADER => false,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_ENCODING => "",
- CURLOPT_AUTOREFERER => true,
- CURLOPT_SSL_VERIFYHOST => 0,
- CURLOPT_SSL_VERIFYPEER => 0,
- CURLOPT_USERAGENT => "",
- CURLOPT_COOKIESESSION => false,
- );
- //Go go go!
- $ch=curl_init($url);
- curl_setopt_array( $ch, $options );
- $output['content'] = curl_exec( $ch );
- /* $output['err'] = curl_errno( $ch );
- $output['errmsg'] = curl_error( $ch );
- $output['header'] = curl_getinfo( $ch );*/
- $doc = new DOMDocument;
- @$doc->loadHTML($output['content']);
- $doc->preserveWhiteSpace = false;
- $xpath = new DOMXpath($doc);
- $city=array();
- if($_REQUEST['index']<0 OR !isset($_REQUEST['index'])){
- $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city='',sr_price='',rto_price='',ins_price='' WHERE varient_id=".$_REQUEST['varient_id'];
- if(mysqli_query($con,$sql)){
- echo "<h4 style='color:green'>Record Removed successfully</h4>";
- }
- else{
- echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
- echo "</div>";
- }
- $brand_id=0;
- $brand=str_replace('-',' ',trim($_REQUEST['brand']));
- $sql2_apr="SELECT id,brand_name FROM vehicle_brands WHERE brand_name='".$brand."'";
- if($result=mysqli_query($con,$sql2_apr))
- {
- echo $total_city=mysqli_num_rows($result);
- while($row=mysqli_fetch_row($result))
- {
- $brand_id=$row[0];
- //array_push($city,$data);
- //var_dump($row);
- }
- }
- $sql2_apr="SELECT city_id,city_name FROM cities WHERE FIND_IN_SET ($brand_id,active_dealers)";
- if($result=mysqli_query($con,$sql2_apr))
- {
- echo $total_city=mysqli_num_rows($result);
- while($row=mysqli_fetch_row($result))
- {
- $data=$row[1];
- array_push($city,$data);
- //var_dump($row);
- }
- }
- //var_dump($city);
- $_SESSION['city_name']=$city;
- echo "City session started..........................";
- //var_dump($_SESSION['city_name']);
- //exit();
- }
- else
- $varient=$_REQUEST['varient'];
- echo $varient=str_replace(' ','-',$varient);
- $nodeList = $xpath->query("//tbody[@class='".$varient."']");
- foreach($nodeList as $val=> $node){
- $prices=$node->nodeValue;
- var_dump($prices);
- $data=explode('₹',$prices);
- //var_dump($data);
- echo "<br> Ex_showroom_price =>";
- $price=explode('.',$data[1]);
- $Ex_showroom_price=trim(str_replace('RTO','',str_replace('*','',str_replace(',','',$price[0]))));
- echo $Ex_showroom_price=preg_replace("/[^0-9]/","",$Ex_showroom_price);
- echo "<br> rto_price =>";
- $rto_price=explode('.',$data[2]);
- $rto_price=trim(str_replace('Insurance','',str_replace(',','',$rto_price[0])));
- echo $rto_price=preg_replace("/[^0-9]/","",$rto_price);
- echo "<br> Insurance_price=>";
- $Insurance_price=explode('.',$data[3]);
- $Insurance_price=trim(str_replace('Others','',str_replace(',','',str_replace('-','',$Insurance_price[0]))));
- echo $Insurance_price=preg_replace("/[^0-9]/","",$Insurance_price);
- echo "<br> other_price=>";
- $other_price=explode('.',$data[4]);
- echo $other_price=preg_replace("/[^0-9]/","",$other_price[0]);
- echo "<br>";
- $index=$_REQUEST['index']+1;
- echo $city=$_SESSION['city_name'][$index];
- //exit();
- $city=strtolower(str_replace('-',' ',str_replace('(','-',str_replace(')','',$city))));
- $new_cityname=$city;
- $value=str_replace('-',' ',$city);
- $sql="SELECT * FROM cities WHERE city_name='".$new_cityname."'";
- $id ='';
- $city_price ='';
- $value=str_replace('-',' ',$value);
- if(strlen($new_cityname)>2){
- $sql2 ="INSERT INTO cities (city_name)
- VALUES ('$new_cityname')";
- if ($con->query($sql2) === TRUE) {
- echo "<br><h1 style='color:green'>New City created successfully!!!</h1>";
- } else{
- //echo "<br><h1 style='color:red'>City name already in table</h1>";
- }
- }
- if($result=mysqli_query($con,$sql))
- {
- // Fetch one and one row
- $row=mysqli_fetch_row($result);
- echo $new_cityname.'';
- echo $id=$row[0];
- $city_price=trim($Ex_showroom_price);
- $insurance=trim($Insurance_price);
- $rto=trim($rto_price);
- $variant=$_REQUEST['varient_id'];
- if ($city_price!=null){
- $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city=CONCAT_WS(',', city, '$id'),sr_price=CONCAT_WS(',', sr_price, '$city_price'),rto_price=CONCAT_WS(',', rto_price, '$rto'),ins_price=CONCAT_WS(',', ins_price, '$insurance') WHERE varient_id=".$variant;
- if(mysqli_query($con,$sql)){
- echo "<h4 style='color:green'>Record updated successfully</h4>";
- }else{
- echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
- echo "</div>";
- }
- }
- }
- $sql="SELECT city,sr_price,rto_price,ins_price FROM vehicals_type_brand_model_varient_vehicle WHERE varient_id=".$variant;
- if ($result=mysqli_query($con,$sql))
- {
- while ($row=mysqli_fetch_row($result))
- {
- $new_city=explode(',',$row[0]);
- $new_price=explode(',',$row[1]);
- $new_ins=explode(',',$row[2]);
- $new_rto=explode(',',$row[3]);
- if ($new_price[0]==null){
- $new_city=$new_city[1];
- $new_price=$new_price[1];
- $new_ins=$new_ins[1];
- $new_rto=$new_rto[1];
- $sql="UPDATE vehicals_type_brand_model_varient_vehicle SET city='{$new_city}',sr_price='{$new_price}',rto_price='{$new_rto}',ins_price='{$new_ins}' WHERE varient_id=".$variant;
- if(mysqli_query($con,$sql)){
- echo "<h4 style='color:green'>Record updated successfully</h4>";
- }
- else{
- echo "<div style='background-color:red;color:red'><h1>ERROR</h1>";
- echo "</div>";
- }
- echo $new_price[1];
- echo $new_ins[1];
- echo $new_rto[1];
- }
- }
- }
- echo '<h4>'.$variant.'</h4>';
- //var_dump($prices);
- echo "<hr>";
- }
- return $output;
- }
- ?>
Add Comment
Please, Sign In to add comment