Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:06

0001 <?php
0002 require_once('./configurations.php');
0003 
0004 $servername = $FEconfig['dbhost'];
0005 $username = $FEconfig['dbuser'];
0006 $password = $FEconfig['dbpass'];
0007 $dbname = $FEconfig['dbname'];
0008 
0009 // Create connection
0010 $conn = new mysqli($servername, $username, $password, $dbname);
0011 
0012 // Check connection
0013 if ($conn->connect_error) {
0014     die("Connection failed: " . $conn->connect_error);
0015 }
0016 
0017 $sql = "SELECT * FROM PlotGroups ORDER BY Type, Name;";
0018 $result = $conn->query($sql);
0019 
0020 $data = ['Physics' => [], 'Detector' => [],'Reconstruction' => []];
0021 if ($result && $result->num_rows > 0) {
0022     while ($row = $result->fetch_assoc()) {
0023         $entry = ['id' => $row['ID'], 'name' => $row['Name']];
0024         if ($row['Type'] === 'physics') {
0025             $data['Physics'][] = $entry;
0026         } elseif ($row['Type'] === 'detector') {
0027             $data['Detector'][] = $entry;
0028         } elseif ($row['Type'] === 'reconstruction') {
0029             $data['Reconstruction'][] = $entry;
0030         }
0031     }
0032     // Convert the data array to JSON and print it
0033     echo json_encode($data);
0034 } else {
0035     echo json_encode(['error' => 'No results found']);
0036 }
0037 
0038 $conn->close();
0039 ?>