CIM69 - car database

This commit is contained in:
“VeLiTi”
2024-06-14 15:59:01 +02:00
parent c53535b50b
commit 3528be22b8
18 changed files with 1552 additions and 136 deletions

View File

@@ -10,17 +10,9 @@ $pdo = dbConnect($dbname);
//NEW ARRAY
$criterias = [];
$whereclause = 'WHERE type="cartest"';
$whereclause = '';
$clause = '';
//FILTER FOR GROUPBY FILTERS on CAR
$filter1 = '"CarBrand": "';
$filter2 = '"CarType": "';
$filter3 = '"CarVIN": "';
$car_brand = 'SUBSTRING_INDEX(SUBSTRING_INDEX(description, "'.$filter1.'", -1),"'.$filter2.'",1)';
$car_type = 'SUBSTRING_INDEX(SUBSTRING_INDEX(description, "'.$filter2.'", -1),"'.$filter3.'",1)';
//Check for $_GET variables and build up clause
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
@@ -31,12 +23,12 @@ if(isset($get_content) && $get_content!=''){
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list'|| $v[0] =='success_msg'){
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='download' || $v[0] =='list'|| $v[0] =='success_msg'){
//do nothing
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND '.$car_brand.' like :'.$v[0];
$clause .= ' AND (carbrand like :'.$v[0].' OR createdby like :'.$v[0].')';
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
@@ -51,15 +43,23 @@ if(isset($get_content) && $get_content!=''){
//Define Query
if(isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count FROM history '.$whereclause;
$sql = 'SELECT count(*) as count FROM cartest '.$whereclause;
}
elseif(isset($criterias['list']) && $criterias['list'] ==''){
elseif(isset($criterias['list']) && $criterias['list'] =='brand'){
//Request for total rows
$sql = 'SELECT distinct('.$car_brand.') FROM history '.$whereclause;
}
$sql = 'SELECT distinct(carbrand) FROM cartest '.$whereclause;
}
elseif(isset($criterias['list']) && $criterias['list'] =='type'){
//Request for total rows
$sql = 'SELECT distinct(cartype) FROM cartest '.$whereclause;
}
elseif(isset($criterias['download']) && $criterias['download'] ==''){
//Request for total rows
$sql = 'SELECT * FROM cartest '.$whereclause;
}
else {
//SQL for Paging
$sql = "SELECT *, SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter1', -1),'$filter2',1) as carbrand from history $whereclause group by SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter1', -1),'$filter2',1), SUBSTRING_INDEX(SUBSTRING_INDEX(description, '$filter2', -1),'$filter3',1) ORDER BY carbrand DESC LIMIT :page,:num_products";
$sql = "SELECT * from cartest $whereclause ORDER BY carbrand, cartype DESC LIMIT :page,:num_products";
}
$stmt = $pdo->prepare($sql);
@@ -84,13 +84,21 @@ if (!empty($criterias)){
}
}
//------------------------------------------
// Debuglog
//------------------------------------------
if (debug){
$message = $date.';'.$sql.';'.$username;
debuglog($message);
}
//Add paging details
if(isset($criterias['totals']) && $criterias['totals']==''){
$stmt->execute();
$messages = $stmt->fetch();
$messages = $messages[0];
}
elseif(isset($criterias['list']) && $criterias['list']==''){
elseif ((isset($criterias['list']) && $criterias['list']!='') || (isset($criterias['download']) && $criterias['download'] =='')){
//Excute Query
$stmt->execute();
//Get results