jeudi 25 octobre 2018

how to use this php sql on laravel??? (dynamic form field)

<?php
$fields = array(
 array(
 'meta_id' => 'name',
 'display_name' => 'Name'
 ),
 array(
 'meta_id' => 'address',
 'display_name' => 'Address'
 ),
 array(
 'meta_id' => 'cps_name',
 'display_name' => 'CSP Name'
 )
);


$tables = array();
$query_fields = array();
$joins = array();
$fcount = 1;


array_push($query_fields, "reports.*");

foreach ($fields as $key => $value) {
 $table_name = "tables" . $fcount++;
 array_push($query_fields, $table_name.".".$value['meta_id']." AS ".$value['display_name']);

 array_push($joins, "INNER JOIN reports_meta_values ".$table_name." ON reports.id = ".$table_name.".report_id AND ".$table_name.".meta_id='".$value['meta_id']."'");
}


$final_sql = "SELECT " .implode(",", $query_fields) . " FROM reports " . implode(" ", $joins). " WHERE 1";

echo "$final_sql";

?>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire