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