dongzhou4727 2014-12-22 05:41
浏览 53
已采纳

试图在Smarty中获取数组表和数据库

I Have an array of Databases and Tables from MySQL. I Can't Seem to Get a List of Tables under each database in Smarty? I Have tried multiple foreach statements and none seem to work. The Database Name shows correct but the tables do not. I appreciate all of the help.

My PHP:

$conn = connect();

$db_sql = $conn->query("SHOW DATABASES;");
$dbs = array();
while ($db = $db_sql->fetch_array(MYSQLI_NUM))
{
    $db_name = $db[0];
    $dbs[] = $db_name;
}

$tables = array();
foreach ($dbs as $db => $value) {
    $table_sql = $conn->query("SHOW TABLES FROM $value");
    while ($table_ = $table_sql->fetch_array(MYSQLI_NUM))
    {
        $tb_name = $table_[0];
        $tables[$value]['Tables'][] = $tb_name;
    }
}

$smarty->assign("dbs", $tables);

My Smarty:

 {foreach from=$dbs key=db item=value}
                    <li>
                        <a class="tree-toggler nav-header" href="#" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-th-list"></span> {$db}</a>
                        <ul class="nav nav-list tree">
                        {foreach from=$value->Tables  item=$table}
                            <li><a href="#">{$table}</a></li>
                        {/foreach}
                        </ul>
                    </li>
                {/foreach}
  • 写回答

1条回答 默认 最新

  • duanjian5059 2014-12-22 09:35
    关注

    The problem is with your smarty code in the second foreach loop

    Replace

    This line of your code - {foreach from=$value->Tables item=$table} WITH This line - {foreach from=$value.Tables item=table}

    And it will be working

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教