Je suis tout débutant en PHP et j'ai bidouillé un peu partout sans solution.
En fait, j'ai un script codé qui marchait avec mon site local sous PHP 5.3 et depuis j'ai changé de CMS qui marche avec du PHP 5.6 ou 7.0 et là vous convenez avec moi que le mysql est depracated il faut donc utiliser Mysqli ou PDO pour que ça marche.
J'ai cherché en vain des correspondance maintenant je prend le risque de vous envoyer mon script si quelqu'un peut m'aider à le faire exécuter sous PDO je lui serai reconnaissant si longtemps.$
Code : Tout sélectionner
<?php
$aujourdhui=date("Y-n-j");
$sql = "SELECT DISTINCT nom,date_depart_saf,date_retour_saf,pays,date1,date2 FROM ma_table WHERE actif='Y' AND ";
$sql .= "((validation <'9' AND date_depart_saf<='" . $aujourdhui . "' AND date_retour_saf>='" . $aujourdhui . "') OR ";
$sql .= " (type='2' AND date1<='" . $aujourdhui . "' AND date2>='" . $aujourdhui . "')) ORDER BY nom";
$base = mysqli_connect ('localhost', 'root', 'ma_base','');
mysqli_select_db ( $link , 'ma_base' );
$ma_requete = mysql_query($sql);
echo mysql_error();
if ($ma_requete) {
$nbrow=mysql_num_rows($ma_requete);
$affichage_php .= "<p style='padding-left:8pt; font:arial; color:blue'><b><u>Liste des absences du jour</u></b> : les dates de départ et de retour sont celles du billet d'avion ou de la demande d'absence</p><table id='rounded-corner' summary='Absences de la période'>
<thead>
<tr>
<th scope='col' class='rounded-top-left'>Nom de l'agent</th>
<th scope='col' class='rounded-pays'>Pays</th>
<th scope='col' class='rounded-depart'>Date de départ</th>
<th scope='col' class='rounded-top-right'>Date de retour</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan='3' class='rounded-foot-left'><em><a href='http://mon_site/intranet/index.php?option=com_content&view=article&id=93'>Pour plus d'information, merci de consulter la page des absences</a></em></td>
<td class='rounded-foot-right'> </td>
</tr>
</tfoot>
<tbody>";
if( $nbrow > 0) {
$i=1;
while ($mon_resultat = mysqli_fetch_array($ma_requete)) {
//$affichage_php .= "<b>" . $mon_resultat["nom"] . "</b> (><i>" . date("d-m-Y",strtotime($mon_resultat["date2"])) . "</i>)";
//$affichage_php .= ($i++<$nbrow?", ":"");
$affichage_php .= "<tr>";
$affichage_php .= "<td>".$mon_resultat["nom"]."</td>";
if (($mon_resultat["pays"] != 'n/a')) {
$pays = $mon_resultat["pays"];
$req = mysqli_query("select pays from table_liste_pays where code3='$pays'");
$res = @mysqli_fetch_array($req);
if (isset($res["pays"])) $pays = $res["pays"];
$affichage_php .= "<td>".$pays."</td>";
$affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date_depart_saf"]))."</td>";
$affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date_retour_saf"]))."</td>";
}else {
$pays = "En congés";
$affichage_php .= "<td>".$pays."</td>";
$affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date1"]))."</td>";
$affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date2"]))."</td>";
}
$affichage_php .= "</tr>";
}
}
else {
//$affichage_php .= "<div class='texte' style='padding-left:8pt; font:arial; color:blue'>>> <u>Absence(s) du jour:</u> ";
$affichage_php .="<i>aucune...</i>";
//$affichage_php .= "</div><br>";
}
$affichage_php .= "</tbody></table>";
}
$aujourdhui=date("Y-n-j");
$sql = "SELECT DISTINCT nom,date1,date2,date_depart_saf,date_retour_saf,pays FROM ma_table WHERE actif='Y' AND ";
$sql .= "((validation = '1' AND type='1') OR (validation = '0' AND type='2')) AND date1>'" . $aujourdhui . "' OR date_depart_saf>'" . $aujourdhui . "' ORDER BY nom";
$ma_requete = mysql_query($sql);
echo mysql_error();
if ($ma_requete) {
$nbrow=mysqli_num_rows($ma_requete);
$affichage_php .= "<p></p><p style='padding-left:8pt; font:arial; color:blue'><b><u>Liste des absences à venir</u></b> : les demandes ci-dessous ont été autorisées par la Direction Générale</p><table id='rounded-corner' summary='Absences de la période'>
<thead>
<tr>
<th scope='col' class='rounded-top-left'>Nom de l'agent</th>
<th scope='col' class='rounded-pays'>Pays</th>
<th scope='col' class='rounded-depart'>Départ probable</th>
<th scope='col' class='rounded-top-right'>Retour probable</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan='3' class='rounded-foot-left'><em><a href='http://mon_site/intranet/index.php?option=com_content&view=article&id=93'>Pour plus d'information, merci de consulter la page des absences</a></em></td>
<td class='rounded-foot-right'> </td>
</tr>
</tfoot>
<tbody>";
if( $nbrow > 0) {
$i=1;
while ($mon_resultat = mysqli_fetch_array($ma_requete)) {
//$affichage_php .= "<b>" . $mon_resultat["nom"] . "</b> (><i>" . date("d-m-Y",strtotime($mon_resultat["date2"])) . "</i>)";
//$affichage_php .= ($i++<$nbrow?", ":"");
$pays = $mon_resultat["pays"];
$req = mysqli_query("select pays from table_liste_pays where code3='$pays'");
//echo var_dump($pays)." ".var_dump($req)."<br />";
$res = mysqli_fetch_array($req);
if (isset($res["pays"])) $pays = $res["pays"];
else $pays = "En congés";
$affichage_php .= "<tr>";
$affichage_php .= "<td>".$mon_resultat["nom"]."</td>";
$affichage_php .= "<td>".$pays."</td>";
if ($mon_resultat["date_depart_saf"] != '0000-00-00') $affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date_depart_saf"]))."</td>";
else $affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date1"]))."</td>";
if ($mon_resultat["date_retour_saf"] != '0000-00-00') $affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date_retour_saf"]))."</td>";
else $affichage_php .= "<td>".date("d / m / Y",strtotime($mon_resultat["date2"]))."</td>";
$affichage_php .= "</tr>";
}
}
else {
//$affichage_php .= "<div class='texte' style='padding-left:8pt; font:arial; color:blue'>>> <u>Absence(s) du jour:</u> ";
$affichage_php .="<i>aucune...</i>";
//$affichage_php .= "</div><br>";
}
$affichage_php .= "</tbody></table>";
}
echo $affichage_php;
?>Merci