Loop nidificazione e sto ottenendo una pagina vuota (php)
-
05-07-2019 - |
Domanda
Ecco cosa ho preso-
$awards_sql_1 = mysql_query('SELECT * FROM categories WHERE section_id = 1') or die(mysql_error());
$awards_rows_1 = mysql_num_rows($awards_sql_1);
$awards_sql_2 = mysql_query('SELECT * FROM categories WHERE section_id = 2') or die(mysql_error());
$awards_sql_3 = mysql_query('SELECT * FROM categories WHERE section_id = 3') or die(mysql_error());
$awards_sql_4 = mysql_query('SELECT * FROM categories WHERE section_id = 4') or die(mysql_error());
$i = 0;
$records = mysql_num_rows($sections_query);
while($row_sections = mysql_fetch_array($sections_query)) {
echo "<h3>" . $row_sections['section_name'] . "</h3>";
echo "<ul>";
//while($categories = mysql_fetch_array($awards_sql_1)) {
for ($i = 0; $i < $awards_rows_1; $i++) {
echo "<li><strong>$categories['category_name']</strong>";
}
echo "</ul>";
}
Per qualche ragione, se commento for () annidato nel mentre (), la pagina si caricherà bene e vedrò tutti i miei h3, tuttavia, ogni volta che provo a nidificare un for () o mentre () all'interno dell'originale while (), la pagina diventa vuota quando viene ricaricata.
Cosa sto sbagliando?
Soluzione
È necessario inserire parentesi graffe attorno alle variabili dell'array incorporate nelle stringhe, altrimenti viene visualizzato un errore di analisi.
echo "<li><strong>{$categories['category_name']}</strong>";
http://php.net /manual/en/language.types.string.php#language.types.string.parsing
Altri suggerimenti
Prova con, otterrai l'errore:
<?php
error_reporting(E_ALL);
...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow