upd mysqltojson
This commit is contained in:
parent
8ab97a222f
commit
69bd9237da
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
include('../../Connections/repnew.php');
|
||||
|
||||
// Connessione al database
|
||||
$conn = new mysqli($servername, $username, $password, $database);
|
||||
|
||||
|
||||
|
||||
// Controlla la connessione
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
@ -61,7 +61,7 @@ $sql = "SELECT
|
||||
pt.partsMaterial,
|
||||
|
||||
a.idAnalysis_Project,
|
||||
a.result_TestName,
|
||||
av.nameanalysisvoc, -- Nome dell'analisi
|
||||
a.test_Rating,
|
||||
a.test_Rating2,
|
||||
a.requirements,
|
||||
@ -69,7 +69,7 @@ $sql = "SELECT
|
||||
a.analysisgroupcode,
|
||||
|
||||
rs.idResult_Project,
|
||||
rs.result_AnalytsName,
|
||||
cv.namecompoundsvocabulary, -- Nome del composto
|
||||
rs.result_AnalytsRating,
|
||||
rs.result_Value,
|
||||
rs.result_Comment,
|
||||
@ -87,8 +87,12 @@ LEFT JOIN
|
||||
parts pt ON r.idreports = pt.idreports
|
||||
LEFT JOIN
|
||||
analysis_project a ON pt.idParts = a.idPart
|
||||
LEFT JOIN
|
||||
analysisvocabulary av ON a.result_TestName = av.idanalysisvocabulary -- Left Join con analysisvocabulary
|
||||
LEFT JOIN
|
||||
result_project rs ON a.idAnalysis_Project = rs.idanalysis_project
|
||||
LEFT JOIN
|
||||
compundsvocabulary cv ON rs.result_AnalytsName = cv.idcompoundsvocabulary -- Left Join con compundsvocabulary
|
||||
WHERE
|
||||
p.products_refnumber = ?";
|
||||
|
||||
@ -105,8 +109,12 @@ $data = array(
|
||||
'product' => array()
|
||||
);
|
||||
|
||||
$reports = array();
|
||||
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
// Se il prodotto non è stato ancora inserito, aggiungilo
|
||||
if (empty($data['product'])) {
|
||||
$data['product'] = array(
|
||||
'products_refnumber' => $row['products_refnumber'],
|
||||
'products_description' => $row['products_description'],
|
||||
@ -133,9 +141,11 @@ if ($result->num_rows > 0) {
|
||||
'products_region' => $row['products_region'],
|
||||
'reports' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Aggiungi i report
|
||||
$report = array(
|
||||
// Controlla se il report è già presente
|
||||
if (!isset($reports[$row['idreports']])) {
|
||||
$reports[$row['idreports']] = array(
|
||||
'reportsNumberLab' => $row['reportsNumberLab'],
|
||||
'reportDateIn' => $row['reportDateIn'],
|
||||
'reportsDateOut' => $row['reportsDateOut'],
|
||||
@ -150,19 +160,23 @@ if ($result->num_rows > 0) {
|
||||
'reports_invoiceadate' => $row['reports_invoiceadate'],
|
||||
'parts' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Aggiungi le parti
|
||||
$part = array(
|
||||
// Controlla se la parte è già presente per il report
|
||||
if (!isset($reports[$row['idreports']]['parts'][$row['idParts']])) {
|
||||
$reports[$row['idreports']]['parts'][$row['idParts']] = array(
|
||||
'partsCode' => $row['partsCode'],
|
||||
'partsDescription' => $row['partsDescription'],
|
||||
'partsColor' => $row['partsColor'],
|
||||
'partsMaterial' => $row['partsMaterial'],
|
||||
'analyses' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Aggiungi le analisi
|
||||
$analysis = array(
|
||||
'result_TestName' => $row['result_TestName'],
|
||||
// Controlla se l'analisi è già presente per la parte
|
||||
if (!isset($reports[$row['idreports']]['parts'][$row['idParts']]['analyses'][$row['idAnalysis_Project']])) {
|
||||
$reports[$row['idreports']]['parts'][$row['idParts']]['analyses'][$row['idAnalysis_Project']] = array(
|
||||
'result_TestName' => $row['nameanalysisvoc'], // Nome dell'analisi
|
||||
'test_Rating' => $row['test_Rating'],
|
||||
'test_Rating2' => $row['test_Rating2'],
|
||||
'requirements' => $row['requirements'],
|
||||
@ -170,10 +184,11 @@ if ($result->num_rows > 0) {
|
||||
'analysisgroupcode' => $row['analysisgroupcode'],
|
||||
'results' => array()
|
||||
);
|
||||
}
|
||||
|
||||
// Aggiungi i risultati
|
||||
// Aggiungi i risultati all'analisi
|
||||
$result_data = array(
|
||||
'result_AnalytsName' => $row['result_AnalytsName'],
|
||||
'result_AnalytsName' => $row['namecompoundsvocabulary'], // Nome del composto
|
||||
'result_AnalytsRating' => $row['result_AnalytsRating'],
|
||||
'result_Value' => $row['result_Value'],
|
||||
'result_Comment' => $row['result_Comment'],
|
||||
@ -184,16 +199,11 @@ if ($result->num_rows > 0) {
|
||||
'reference' => $row['result_reference']
|
||||
);
|
||||
|
||||
// Inserisci i risultati nell'analisi
|
||||
$analysis['results'][] = $result_data;
|
||||
$reports[$row['idreports']]['parts'][$row['idParts']]['analyses'][$row['idAnalysis_Project']]['results'][] = $result_data;
|
||||
}
|
||||
|
||||
// Inserisci l'analisi nella parte
|
||||
$part['analyses'][] = $analysis;
|
||||
|
||||
// Inserisci la parte nel report
|
||||
$report['parts'][] = $part;
|
||||
|
||||
// Inserisci il report nel prodotto
|
||||
// Aggiungi i report finali al prodotto
|
||||
foreach ($reports as $report) {
|
||||
$data['product']['reports'][] = $report;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user