Affichage d'un tableau
Posté : 03 nov. 2022, 11:36
Bonjour,
je suis nouveau dans le développement web et j'ai un petit souci pour construire mon rapport journalier.
J'essaie d'afficher un tableau avec différentes informations. Aujourd'hui mon tableau est coupé en deux.
Résultat actuel:
Array
(
[0] =>
4016035
TEC
08/09/2022
DEC35.0404. BANDE TRANSPORTEUSE
D
PE
31:53
moteur bruyant
Bruit
moteur bruyant
Semble provenir du moteur roulement
[7] =>
4016137
TEC
29/09/2022
EXP04.0020. ITALCARRELLI 6T2
D
PB
1:39
Fourches du 6T2 désynchronisées l'une par rapport à l'autre.
Sortie des fourches par l'opérateur expédition
[8] =>
4016249
TEC
26/10/2022
EXP04.0017. ITALCARRELLI 16T3
D
PC
0:30
Remise en état des fourches
Remise en etat des fourches
remplacement
[14] =>
4016035
27/10/2022
DUPONT ANTOINE
5:0
[15] =>
4016035
27/10/2022
DUPONT TEST
5:0
[16] =>
4016035
27/10/2022
TEST TEST1
5:0
[17] =>
4016035
27/10/2022
TEST TEST2
5:0
[18] =>
4016035
27/10/2022
TEST TEST3
5:0
[19] =>
4016035
27/10/2022
ARTHUR TITI
1:0
[20] =>
4016035
27/10/2022
NOM PRENOM
1:0
[21] =>
4016137
27/10/2022
PRENOM NOM
0:30
Je voudrai fusionner mes deux tableaux.
Si NU_NUMBT sont égaux alors affiche moi la ligne sous le bon rapport.
Résultat voulu:
Array
(
[0] =>
4016035
TEC
08/09/2022
DEC35.0404. BANDE TRANSPORTEUSE
D
PE
31:53
moteur bruyant
Bruit
moteur bruyant
Semble provenir du moteur roulement
[14] =>
4016035
27/10/2022
DUPONT ANTOINE
5:0
[15] =>
4016035
27/10/2022
DUPONT TEST
5:0
[16] =>
4016035
27/10/2022
TEST TEST1
5:0
[17] =>
4016035
27/10/2022
TEST TEST2
5:0
[18] =>
4016035
27/10/2022
TEST TEST3
5:0
[19] =>
4016035
27/10/2022
ARTHUR TITI
1:0
[20] =>
4016035
27/10/2022
NOM PRENOM
1:0
[7] =>
4016137
TEC
29/09/2022
EXP04.0020. ITALCARRELLI 6T2
D
PB
1:39
Fourches du 6T2 désynchronisées l'une par rapport à l'autre.
Sortie des fourches par l'opérateur expédition
[21] =>
4016137
27/10/2022
PRENOM NOM
0:30
[8] =>
4016249
TEC
26/10/2022
EXP04.0017. ITALCARRELLI 16T3
D
PC
0:30
Remise en état des fourches
Remise en etat des fourches
remplacement
Ci-dessous mon code actuel
je suis nouveau dans le développement web et j'ai un petit souci pour construire mon rapport journalier.
J'essaie d'afficher un tableau avec différentes informations. Aujourd'hui mon tableau est coupé en deux.
Résultat actuel:
Array
(
[0] =>
4016035
TEC
08/09/2022
DEC35.0404. BANDE TRANSPORTEUSE
D
PE
31:53
moteur bruyant
Bruit
moteur bruyant
Semble provenir du moteur roulement
[7] =>
4016137
TEC
29/09/2022
EXP04.0020. ITALCARRELLI 6T2
D
PB
1:39
Fourches du 6T2 désynchronisées l'une par rapport à l'autre.
Sortie des fourches par l'opérateur expédition
[8] =>
4016249
TEC
26/10/2022
EXP04.0017. ITALCARRELLI 16T3
D
PC
0:30
Remise en état des fourches
Remise en etat des fourches
remplacement
[14] =>
4016035
27/10/2022
DUPONT ANTOINE
5:0
[15] =>
4016035
27/10/2022
DUPONT TEST
5:0
[16] =>
4016035
27/10/2022
TEST TEST1
5:0
[17] =>
4016035
27/10/2022
TEST TEST2
5:0
[18] =>
4016035
27/10/2022
TEST TEST3
5:0
[19] =>
4016035
27/10/2022
ARTHUR TITI
1:0
[20] =>
4016035
27/10/2022
NOM PRENOM
1:0
[21] =>
4016137
27/10/2022
PRENOM NOM
0:30
Je voudrai fusionner mes deux tableaux.
Si NU_NUMBT sont égaux alors affiche moi la ligne sous le bon rapport.
Résultat voulu:
Array
(
[0] =>
4016035
TEC
08/09/2022
DEC35.0404. BANDE TRANSPORTEUSE
D
PE
31:53
moteur bruyant
Bruit
moteur bruyant
Semble provenir du moteur roulement
[14] =>
4016035
27/10/2022
DUPONT ANTOINE
5:0
[15] =>
4016035
27/10/2022
DUPONT TEST
5:0
[16] =>
4016035
27/10/2022
TEST TEST1
5:0
[17] =>
4016035
27/10/2022
TEST TEST2
5:0
[18] =>
4016035
27/10/2022
TEST TEST3
5:0
[19] =>
4016035
27/10/2022
ARTHUR TITI
1:0
[20] =>
4016035
27/10/2022
NOM PRENOM
1:0
[7] =>
4016137
TEC
29/09/2022
EXP04.0020. ITALCARRELLI 6T2
D
PB
1:39
Fourches du 6T2 désynchronisées l'une par rapport à l'autre.
Sortie des fourches par l'opérateur expédition
[21] =>
4016137
27/10/2022
PRENOM NOM
0:30
[8] =>
4016249
TEC
26/10/2022
EXP04.0017. ITALCARRELLI 16T3
D
PC
0:30
Remise en état des fourches
Remise en etat des fourches
remplacement
Ci-dessous mon code actuel
require_once('TCPDF-main/tcpdf.php');
blablabla
$serverName = "serveur"; //serverName\instanceName
$connectionInfo = array( "Database"=>"xxx", "UID"=>"xxx", "PWD"=>"xxx", "CharacterSet" => "UTF-8");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$sql="SELECT B.NU_NUMBT, B.ST_ETA, ISNULL(B.DT_DEM,0) AS DT_DEM, EQU.ST_CODLON, EQU.ST_DESEQU, B.ID_CODTRA, B.ID_CODINT, ISNULL(B.NU_HEUREA,0) AS NU_HEUREA , B.ST_TRADEM, B.ST_TRA, ISNULL(D.DT_TEM,0) AS DT_TEM, ISNULL(D.NU_TOTHEU,0) AS NU_TOTHEU, INTER.ST_PRE, INTER.ST_NOM, A.OL_DOC AS RAPPORT1, C.OL_DOC AS RAPPORT2 FROM BT B LEFT OUTER JOIN TEM D ON D.ID_NUMBT=B.ID_NUMBT AND D.DT_TEM BETWEEN '2022/10/27' AND '2022/10/28' LEFT OUTER JOIN INTER ON INTER.ID_CODINT=D.ID_CODINT JOIN EQU ON EQU.ID_NUMEQU=B.ID_NUMEQU LEFT OUTER JOIN BTDOC A ON A.ID_NUMDOC=B.ID_NUMDOC LEFT OUTER JOIN BTDOC C ON C.ID_NUMDOC=B.ID_NUMDOC2 where B.DT_ECH='2022/10/27' AND B.ST_ETA NOT LIKE 'P%' ORDER BY B.ST_ETA DESC, B.NU_NUMBT";
$stmt= sqlsrv_query($conn,$sql);
$table = <<<EOD
<table width="600" cellpadding="1" cellspacing="1">
<tr style="background-color:#0000FF;color:#FFFFFF;">
<th width="50" align="center"><b>Travail</b></th>
<th width="50" align="center"><b>Etat</b></th>
<th width="50" align="center"><b>Date</b></th>
<th width="300" align="center"> <b>Machine</b></th>
<th width="50" align="center"><b>Type</b></th>
<th width="50" align="center"><b>Exec</b></th>
<th width="50" align="center"> <b>H.Rea</b></th>
</tr>
%s
</table>
EOD;
$tr = <<<EOD
<tr>
<td border="1" width="50">%s</td>
<td border="1" width="50">%s</td>
<td border="1" width="50">%s</td>
<td border="1" width="300">%s %s</td>
<td border="1" width="50">%s</td>
<td border="1" width="50">%s</td>
<td border="1" width="50">%s:%s</td>
</tr>
<tr>
<td width="300">%s</td>
<td width="300">%s</td>
</tr>
<tr>
<td width="300">%s</td>
<td width="300">%s</td>
</tr>
<br /><br />
EOD;
$tr1 = <<<EOD
<tr style="background-color:#0000FF;color:#FFFFFF;">
<td width="50">%s</td>
<td width="50">%s</td>
<td width="130">%s %s</td>
<td width="20">%s:%s</td>
</tr>
EOD;
while ($row = sqlsrv_fetch_Array($stmt,SQLSRV_FETCH_ASSOC)){
$plain = $row['RAPPORT1'];
$plain = preg_replace( '/\r|\n/', '', $plain);
$imgHtml = '';
$imgMatches = array();
$imgRegex = '/{\\\\pict\\\\pngblip\\\\[a-z0-9]+\\\\[a-z0-9]+\\\\[a-z0-9]+\\\\[a-z0-9]+ ([a-z0-9]+)}/';
preg_match_all($imgRegex, $plain, $imgMatches);
if (count($imgMatches[1])) {
for ($i=0; $i < count($imgMatches[1]); $i++) {
$imgHtml .= '<img src="data:image/png;base64, ' . base64_encode(pack('H*', $imgMatches[1][$i])) . '">';
}
}
$plain = preg_replace($imgRegex, '', $plain);
$plain = preg_replace('"{\*?\\\\.+(;})|\\s?\\\[A-Za-z0-9]+|\\s?{\\s?\\\[A-Za-z0-9‹]+\\s?|\\s?}\\s?"', '', $plain);
$plain = str_replace("\'3f", '?', $plain);
$plain = str_replace("\'80", '€', $plain);
$plain = str_replace("\'a8", '¨', $plain);
$plain = str_replace("\'ab", '«', $plain);
$plain = str_replace("\'ae", '®', $plain);
$plain = str_replace("\'b0", '°', $plain);
$plain = str_replace("\'bb", '»', $plain);
$plain = str_replace("\'c4", 'Ä', $plain);
$plain = str_replace("\'c9", 'É', $plain);
$plain = str_replace("\'d6", 'Ö', $plain);
$plain = str_replace("\'dc", 'Ü', $plain);
$plain = str_replace("\'df", 'ß', $plain);
$plain = str_replace("\'e0", 'à', $plain);
$plain = str_replace("\'e2", 'â', $plain);
$plain = str_replace("\'e4", 'ä', $plain);
$plain = str_replace("\'e7", 'ç', $plain);
$plain = str_replace("\'e8", 'è', $plain);
$plain = str_replace("\'e9", 'é', $plain);
$plain = str_replace("\'ea", 'ê', $plain);
$plain = str_replace("\'eb", 'ë', $plain);
$plain = str_replace("\'ee", 'î', $plain);
$plain = str_replace("\'f4", 'ô', $plain);
$plain = str_replace("\'f6", 'ö', $plain);
$plain = str_replace("\'f8", 'ø', $plain);
$plain = str_replace("\'fb", 'û', $plain);
$plain = str_replace("\'fc", 'ü', $plain);
$plain = trim($plain);
$plain = preg_replace('/^-0 /', '', $plain);
$plain .= $imgHtml;
$rapport2 = $row['RAPPORT2'];
$rapport2 = preg_replace( '/\r|\n/', '', $rapport2);
$imgHtml = '';
$imgMatches = array();
$imgRegex = '/{\\\\pict\\\\pngblip\\\\[a-z0-9]+\\\\[a-z0-9]+\\\\[a-z0-9]+\\\\[a-z0-9]+ ([a-z0-9]+)}/';
preg_match_all($imgRegex, $rapport2, $imgMatches);
if (count($imgMatches[1])) {
for ($i=0; $i < count($imgMatches[1]); $i++) {
$imgHtml .= '<img src="data:image/png;base64, ' . base64_encode(pack('H*', $imgMatches[1][$i])) . '">';
}
}
$rapport2 = preg_replace($imgRegex, '', $rapport2);
$rapport2 = preg_replace('"{\*?\\\\.+(;})|\\s?\\\[A-Za-z0-9]+|\\s?{\\s?\\\[A-Za-z0-9‹]+\\s?|\\s?}\\s?"', '', $rapport2);
$rapport2 = str_replace("\'3f", '?', $rapport2);
$rapport2 = str_replace("\'80", '€', $rapport2);
$rapport2 = str_replace("\'a8", '¨', $rapport2);
$rapport2 = str_replace("\'ab", '«', $rapport2);
$rapport2 = str_replace("\'ae", '®', $rapport2);
$rapport2 = str_replace("\'b0", '°', $rapport2);
$rapport2 = str_replace("\'bb", '»', $rapport2);
$rapport2 = str_replace("\'c4", 'Ä', $rapport2);
$rapport2 = str_replace("\'c9", 'É', $rapport2);
$rapport2 = str_replace("\'d6", 'Ö', $rapport2);
$rapport2 = str_replace("\'dc", 'Ü', $rapport2);
$rapport2 = str_replace("\'df", 'ß', $rapport2);
$rapport2 = str_replace("\'e0", 'à', $rapport2);
$rapport2 = str_replace("\'e2", 'â', $rapport2);
$rapport2 = str_replace("\'e4", 'ä', $rapport2);
$rapport2 = str_replace("\'e7", 'ç', $rapport2);
$rapport2 = str_replace("\'e8", 'è', $rapport2);
$rapport2 = str_replace("\'e9", 'é', $rapport2);
$rapport2 = str_replace("\'ea", 'ê', $rapport2);
$rapport2 = str_replace("\'eb", 'ë', $rapport2);
$rapport2 = str_replace("\'ee", 'î', $rapport2);
$rapport2 = str_replace("\'f4", 'ô', $rapport2);
$rapport2 = str_replace("\'f6", 'ö', $rapport2);
$rapport2 = str_replace("\'f8", 'ø', $rapport2);
$rapport2 = str_replace("\'fb", 'û', $rapport2);
$rapport2 = str_replace("\'fc", 'ü', $rapport2);
$trs[] = sprintf($tr, $row["NU_NUMBT"],$row["ST_ETA"],$row["DT_DEM"]->format('d/m/Y'),$row["ST_CODLON"],$row["ST_DESEQU"],$row["ID_CODTRA"],$row["ID_CODINT"],$hours,$mins,$row["ST_TRADEM"],$row["ST_TRA"],$plain,$rapport2);
$trs1[] = sprintf ($tr1, $row["NU_NUMBT"], $row["DT_TEM"]->format('d/m/Y'), $row["ST_PRE"], $row["ST_NOM"], $hours_t, $mins_t);
$array = array_unique(array_merge($trs, $trs1));
}
//echo "<pre>";
//print_r($array);
//echo "</pre>"
$tbl = sprintf($table, implode( " ",$array));
$pdf->writeHTML($tbl, true, 0, true, 0, '');
$pdf->output('');