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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失