这是我得到的 -
$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>";
}
出于某种原因,如果我注释掉嵌入在while()中的for(),页面将加载正常,但是,每当我尝试嵌套for()或while时,我会看到所有的h3 ()在原始while()中,页面在重新加载时变为空白。
我做错了什么?
答案 0 :(得分:3)
你需要在字符串中嵌入数组变量的大括号,否则你会得到一个解析错误。
echo "<li><strong>{$categories['category_name']}</strong>";
http://php.net/manual/en/language.types.string.php#language.types.string.parsing
答案 1 :(得分:1)
试试,你会收到错误:
<?php
error_reporting(E_ALL);
...