0

这是我得到的-

    $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(),页面将正常加载,并且我会看到我所有的 h3,但是,每当我尝试在其中嵌套 for() 或 while() 时原来的while(),页面在重新加载时只是空白。

我究竟做错了什么?

4

2 回答 2

3

您需要在嵌入在字符串中的数组变量周围加上大括号,否则会出现解析错误。

 echo "<li><strong>{$categories['category_name']}</strong>";

http://php.net/manual/en/language.types.string.php#language.types.string.parsing

于 2009-07-30T19:16:32.017 回答
1

试试看,你会得到错误:

<?php
error_reporting(E_ALL);
...
于 2009-07-30T19:15:08.713 回答