datalist_vehicle_details

mail@pastecode.io avatar
unknown
php
2 years ago
5.4 kB
1
Indexable
Never
<?php
	include('db/conn.php');
    include('admin_functions.php');
    include('admin_model.php');
	
	$tablename 		= "vehicle_detail";
	$requestData	= $_REQUEST;
	
	//$vehicle_id		= $_REQUEST['vehicle_id'];
	
	$columns = array(
					0 	=>	'id',
					);

	
	$sql = "SELECT 	vehicle_detail.id,
					vehicle_brand_lookup.vehicle_brand,
					vehicle_model_lookup.vehicle_model,
					vehicle_type_lookup.vehicle_type,
					vehicle_color_lookup.vehicle_color,
					vehicle_detail.year_manufactured
			FROM vehicle_detail
			INNER JOIN vehicle_type_lookup
				ON vehicle_detail.vehicle_type_id = vehicle_type_lookup.id
			INNER JOIN vehicle_color_lookup
				ON vehicle_detail.vehicle_color_id = vehicle_color_lookup.id
			INNER JOIN vehicle_brand_model_lookup
				ON vehicle_detail.vehicle_brand_model_id = vehicle_brand_model_lookup.id
			LEFT JOIN vehicle_brand_lookup
				ON vehicle_brand_model_lookup.brand_id = vehicle_brand_lookup.id
			LEFT JOIN vehicle_model_lookup
				ON vehicle_brand_model_lookup.model_id = vehicle_model_lookup.id";
					
	//print $sql;
	
	$rs = $conn->query($sql) or die($conn->error);	
	while($row = $rs->fetch_assoc()) 
	{
		
	}
	
	$query 			= $conn->query($sql);	
	$totalData 		= $query->num_rows;
	$totalFiltered 	= $totalData;  
	
	$sql = "SELECT 	vehicle_detail.id,
					vehicle_brand_lookup.vehicle_brand,
					vehicle_model_lookup.vehicle_model,
					vehicle_type_lookup.vehicle_type,
					vehicle_color_lookup.vehicle_color,
					vehicle_detail.year_manufactured
			FROM vehicle_detail
			INNER JOIN vehicle_type_lookup
				ON vehicle_detail.vehicle_type_id = vehicle_type_lookup.id
			INNER JOIN vehicle_color_lookup
				ON vehicle_detail.vehicle_color_id = vehicle_color_lookup.id
			INNER JOIN vehicle_brand_model_lookup
				ON vehicle_detail.vehicle_brand_model_id = vehicle_brand_model_lookup.id
			LEFT JOIN vehicle_brand_lookup
				ON vehicle_brand_model_lookup.brand_id = vehicle_brand_lookup.id
			LEFT JOIN vehicle_model_lookup
				ON vehicle_brand_model_lookup.model_id = vehicle_model_lookup.id
			WHERE 1=1";	
		
	$search_array = array(
						'',
						'',
						'',
						'',
						);
	
	if( !empty($requestData['search']['value']) ) {
		$sql.=" AND ( id LIKE '%".$requestData['search']['value']."%' ";
		
		foreach ($search_array as $key => $column) {
			$sql.=" OR $column LIKE '%".$requestData['search']['value']."%' ";
		}
		
		$sql.=" OR status LIKE '".$requestData['search']['value']."%' )";
	}
		
    $query			= $conn->query($sql) or die($conn->error);
	$totalData 		= $query->num_rows;
	$totalFiltered 	= $totalData;  
    
    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
    $query	= $conn->query($sql);
	
	//print $sql;
	
	$counter 	= 0;
	$data 		= array();																				
    while($row = $query->fetch_assoc()) 
    {
		$counter++;
		$id 					= $row['id'];	
		
		$vehicle_brand			= $row['vehicle_brand'];
		$vehicle_model			= $row['vehicle_model'];
		
		$vehicle_type			= $row['vehicle_type'];
		$vehicle_color			= $row['vehicle_color'];
		
		$year_manufactured		= $row['year_manufactured'];
		
		$nestedData		= array();
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $id . "</div>";			
		
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $vehicle_brand . "</div>";
									
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $vehicle_model . "</div>";
									
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $vehicle_type . "</div>";
									
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $vehicle_color . "</div>";
									
		$nestedData[] 		= "<div align='left' 
									style='display: inline-block;
									white-space: nowrap;' >" . $year_manufactured . "</div>";
			
		$key	= "cube123";
		
		$menu 	= 126;
		$menu 	= selaktutup($key,$menu);
		$menu 	= rawurlencode($menu);
		
		$menu2 	= 127;
		$menu2 	= selaktutup($key,$menu2);
		$menu2 	= rawurlencode($menu2);
		
		$id 	= selaktutup($key,$id);
		$id 	= rawurlencode($id);
		
		$nestedData[] 		=	"<div align='left' 
									style='display: inline-block;
									white-space: nowrap;'>
									
										<a href='index.php?msa=$menu&id=$id' 
											id='edit_vehicle_brand' 
											value='EDIT' 
											style='border-radius:10px;'
											class='btn btn-success fontYantra''>EDIT</a>
											
										<a href='index.php?msa=$menu2&id=$id' 
											id='assign_vehicle_model' 
											value='REMOVE' 
											style='border-radius:10px;'
											class='btn btn-danger fontYantra''>REMOVE</a>
								</div>";
		 
		 $data[] = $nestedData;
	}

    $json_data = array(
    			"draw"           	=> intval( $requestData['draw'] ),  
    			"recordsTotal"    	=> intval( $totalData ),  				
    			"recordsFiltered" 	=> intval( $totalFiltered ), 			 
    			"data"            	=> $data   								
    			);

    echo json_encode($json_data);
?>