Je voudrais afficher les données d'une table sous forme de tableau, le problème est que cela ne s'affiche pas. Cela me mets code erreur : (!) Avertissement: argument non valide fourni pour foreach () dans C: \ wamp64 \ www \ Livre \ fonctions.php à la ligne 125.
Voici mon code séparer en deux pages:
Ma première page :
Code : Tout sélectionner
$_database = new PDO('mysql:host=localhost;dbname=Livre', 'root','');
function db_selectionner_tous ( $sql, $valeurs=null, $array=null){
global $_database;
$stmt = $_database-> prepare($sql);
$stmt -> execute($valeurs);
html_table();
db_log($stmt);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
function afficher ( $text) {
echo "<pre>";
print_r($text);
echo "</pre>";
}
function html_table($array = null) {
$html = '<table>' ;
// colonnes
$html .= '<tr>nknju';
foreach($array[0] as $key=>$value) {
$html .= '<th>' .$key .'</th>';
}
$html .= '</tr>';
//ligne
foreach ( $array as $key=>$value) {
$html .= '<tr>';
foreach($value as $key2=>$value2)
{
$html .= '</tr>';
}
$html .= '</table>';return $html;
}
Code : Tout sélectionner
case "LISTE_FAMILLE" :
$array = db_selectionner_tous("SELECT * FROM FAMILLE");
html_table($array);
break;