在 HTML 页面中重复某个区域

发布于 2024-09-17 22:58:43 字数 724 浏览 6 评论 0原文

我一直在尝试学习 PHP 重复区域...我搜索了 google 但遇到了非常复杂的代码示例,eg & 例如,我希望有人能提供一个简单的代码示例...就像我正在做的那样,

我有一个查询,它获取结果并生成一个包含结果的列表

$results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");

<ul>
    // The the targeted repeat region starts here
    <li> 
    //my data  
    </li>
    // The target repeat region ends here
</ul>

,我知道我可以用循环来完成此操作,但为什么在重复区域功能存在时还要麻烦...为什么不学习...

ps这个问题是为了让学习变得简单,因为这是一个编程问题,所以不要投票否决:)或投票关闭它;p

i have been trying to learn PHP Repeat Region... i have searched google but came across very complicated code samples, e.g & e.g, i would like if somebody be kind enough to provide a simple code sample... like what i am doing is

i have a query which gets results and makes a list with result

$results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");

<ul>
    // The the targeted repeat region starts here
    <li> 
    //my data  
    </li>
    // The target repeat region ends here
</ul>

i know i can do this with a loop but why bother when repeat region functionality is there...why not learn...

p.s. this question is to make the learning simple and AS it is a programming question don't vote down :) or vote to close it ;p

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

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

发布评论

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

评论(2

单身狗的梦 2024-09-24 22:58:43

这样的事情还不够吗?我不认为没有框架和视图助手会更简单。

<?php
    $results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");
    ?>
    <ul>
        <?php while($array = mysql_fetch_assoc($results)){ ?>
        <li>
        <?php echo $array['names']; ?>
        </li>
        <?php } ?>
    </ul>

Something like that is not enough? I dont think there is simpler without a framework and viewhelpers.

<?php
    $results = mysql_query("SELECT names,age,nic FROM t_able WHERE state='1'");
    ?>
    <ul>
        <?php while($array = mysql_fetch_assoc($results)){ ?>
        <li>
        <?php echo $array['names']; ?>
        </li>
        <?php } ?>
    </ul>
傲娇萝莉攻 2024-09-24 22:58:43

这是一个简单的循环,通常在编程的早期就已经学会了。您可能听说过一些奇怪的术语,这些术语只会让事情变得比实际需要的更加复杂。

// Repeat as long as there is a preceding row
while($row = mysql_fetch_assoc($results))
{
    echo "<li>";
    echo "Names: " . $row["names"]; // Add other data
    echo "</li>";
}

This is a simple loop, which one usually learns quite early on in programming. You may have heard some strange terminology that's just making this more complex than it needs to be.

// Repeat as long as there is a preceding row
while($row = mysql_fetch_assoc($results))
{
    echo "<li>";
    echo "Names: " . $row["names"]; // Add other data
    echo "</li>";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文