【问题标题】:While with PHP Simple Templates [closed]使用 PHP 简单模板时 [关闭]
【发布时间】:2012-08-21 13:29:52
【问题描述】:

我使用了 overthemike (php-templates) 的 php 模板,但它不适用于函数 while (on mysql)...

显示正确的类别:

1.PC
    1.电源
    2.VGA
    3.RAM
    4.音频
2.笔记本电脑
    1.监控
    2.引脚
    3.键盘

运行后:

1.PC
    3.电源
    4.VGA
    5.RAM
    6.音频
    7.监控
    8.引脚
    9.键盘
2.笔记本电脑
    3.电源
    4.VGA
    5.RAM
    6.音频
    7.监控
    8.引脚
    9.键盘

示例:http://www.mediafire.com/?fln71mh5pwqjn7m

为什么代码会填满所有可用空间?

你能帮我修复这个代码吗?

【问题讨论】:

  • 我认为没有人会下载您链接到的文件。谁知道里面有什么?

标签: php template-engine


【解决方案1】:
$data = array();

while($result = mysql_fetch_array($query))
{

    $sql = mysql_query("SELECT * FROM category WHERE sub = ".$result["id"]." ORDER BY id ASC");

    while($resub = mysql_fetch_array($sql))
    {
        $data[$result["title"]][] = array(
            "id"=>$resub["id"],
            "title"=>$resub["title"],
        );

    }

}
print_r($data);

这应该可以。另外我认为您应该使用其他东西,因为这不是您想要实现的目标的好解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-14
    • 2011-08-18
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多