Ich hoffe, Sie verstehen mein Problem, ich weiß nicht viel Englisch, aber ich werde es versuchen. Ich habe eine Seite in einem hostinger und wenn ich den Code generieren, um die Zeilen zu zeigen, gibt mir diese Fehlermeldung:Ungültiges Argument für foreach php pdo in Hostinger
Warning: Invalid argument supplied for foreach()
Anschluss-Code:
public static function conexion() {
try {
$con = new PDO('mysql:host=localhost;dbname=example', 'usuario', 'clave');
return $con;
} catch (PDOException $e) {
return false;
}
}
Und:
include 'functions.php';
$con = Functions::conexion();
$sql = 'SELECT * FROM Products p, Prices ps, ProductsPrices pc where p.IDP=pc.IDP AND ps.ID=pc.ID ORDER BY p.IDP ASC';
foreach ($con->query($sql) as $row) {
echo '<tr>';
echo '<td>'. $row['IDP'] . '</td>';
echo '<td>'. $row['Name'] . '</td>';
echo '<td>'. $row['Description'] . '</td>';
echo '<td style="color: #333;">'. $row['Price'] . '</td>';
echo '<td>' . '<a class="btn" href="update.php?id='.$row['IDP'].'">Edit</a>' . '</td>';
echo '</tr>';
Aber wenn ich in localhost lade, gibt es kein Problem, zeigt die Reihen an.
Hallo, danke fo r antwort, ich versuche ihre lösung und gibt dies: Fatal error: Aufruf an eine Member-Funktion fetchAll() auf einem Nicht-Objekt – forerser