使用 SQL 填充导航选项卡?

发布于 2024-09-12 07:13:53 字数 785 浏览 2 评论 0原文

我正在寻找某种允许由 SQL 填充的导航选项卡(垂直)。例如,在 SQL 表中会有一个标题列(即选项卡的标题)和一个选项卡内容列。

我尝试过自己构建一个,但我不知道如何将其放入导航栏中,因为通常我会做一个 while 循环来用 SQL 填充某些内容,但因为导航有两件事需要填充(< ;li>

位),我不确定该怎么做。

谢谢。

编辑:

    <ul>
<?php
    $query = tep_db_query("select * table1");
    while ($row = mysql_fetch_assoc($query)) {
    echo '<li><a href="#tabs-' . $row['tabid'] . '">' . $row['tabtitle'] . '</a></li>'
    }
    ?>

    </ul>




<?php
    $query2 = tep_db_query("select * table1");
    while ($row = mysql_fetch_assoc($query2)) {
    echo '
    <div id="tabs-' . $row['tabid'] . '">

    <p> ' . $row['tabcontent'] . ' </p>
    '
    }
    ?>

I'm looking for some kind of Nav tab (vertical) that allows it to be populated by SQL. For example, in the SQL table there would be a column for title (which is the title of the tab) and a column for the contents of the tab.

I have tried building one myself, but I have no idea how to fit it in a nav bar because usually I'd do a while loop to populate something with SQL, but because nav's have two things that need populating (the <li> and the <div> bits), I am unsure of how to do it.

Thanks.

Edit:

    <ul>
<?php
    $query = tep_db_query("select * table1");
    while ($row = mysql_fetch_assoc($query)) {
    echo '<li><a href="#tabs-' . $row['tabid'] . '">' . $row['tabtitle'] . '</a></li>'
    }
    ?>

    </ul>




<?php
    $query2 = tep_db_query("select * table1");
    while ($row = mysql_fetch_assoc($query2)) {
    echo '
    <div id="tabs-' . $row['tabid'] . '">

    <p> ' . $row['tabcontent'] . ' </p>
    '
    }
    ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攀登最高峰 2024-09-19 07:13:53

你所拥有的似乎没问题,你也许可以做这样的事情来消除一半的数据库调用。

//Get information from db.
<?php
    $query = tep_db_query("SELECT tabid, tabtitle, tabcontent FROM table1");
    while ($row = mysql_fetch_assoc($query)) {
        $table[] = $row;
    }
?>

<ul>
<?php foreach($table as $row){
    echo '<li><a href="#tabs-' . $row['tabid'] . '">' . $row['tabtitle'] . '</a></li>';
}
?>
</ul>

<?php foreach($table as $row){
    echo '
    <div id="tabs-' . $row['tabid'] . '">

    <p> ' . $row['tabcontent'] . ' </p>
    ';
}
?>

What you have seems like it would be okay, you might be able to do something like this in order to eliminate half of your db calls.

//Get information from db.
<?php
    $query = tep_db_query("SELECT tabid, tabtitle, tabcontent FROM table1");
    while ($row = mysql_fetch_assoc($query)) {
        $table[] = $row;
    }
?>

<ul>
<?php foreach($table as $row){
    echo '<li><a href="#tabs-' . $row['tabid'] . '">' . $row['tabtitle'] . '</a></li>';
}
?>
</ul>

<?php foreach($table as $row){
    echo '
    <div id="tabs-' . $row['tabid'] . '">

    <p> ' . $row['tabcontent'] . ' </p>
    ';
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文