如何显示
根据下面显示的数据计数?

发布于 2024-09-24 15:02:02 字数 934 浏览 1 评论 0原文

我必须根据数据库中可用的数据显示以下代码片段

<div id="testimonial-row">
            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>

            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>

            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>
        </div>

也就是说,每次数据计数(此处为 hello world)变为时,都应创建

大于 3,因此,如果数据计数为“16”,则
应创建 6 次,所有数据显示在创建的 6 次中
标签

那么有人可以告诉我如何实现 for 循环以在 PHP 中实现这一点吗?

I have to display below snippet according to data available in DB

<div id="testimonial-row">
            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>

            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>

            <div id="testimonial">
                <ul>

                    <li>"Hello World"</li>
                </ul>
            </div>
        </div>

That is, the <div id="testimonial-row"> should be created everytime the count of data (here, hello world) becomes greater than 3, hence in this way if the data count is "16" the the <div id="testimonial-row"> should be created 6 times with all the data displayed in created 6 <div> tags

So could some one tell me how to implement the for loop to make this happen in PHP?

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

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

发布评论

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

评论(3

玩世 2024-10-01 15:02:02

如果我正确理解你的问题:

for($z=0;$z<16;$z++)
 {
        if($z==0) print '<div class="testimonial-row">';
        else if($z%3==0) print '</div><div class="testimonial-row">';
        print '<div class="testimonial"><ul><li>"Hello World"</li></ul></div>';
 }
 print '</div>';

If I understand your question correctly:

for($z=0;$z<16;$z++)
 {
        if($z==0) print '<div class="testimonial-row">';
        else if($z%3==0) print '</div><div class="testimonial-row">';
        print '<div class="testimonial"><ul><li>"Hello World"</li></ul></div>';
 }
 print '</div>';
赢得她心 2024-10-01 15:02:02
   echo '<div class="testimonial-row">';
    for ($i=1;$i<=$mysql_num_rows($res);$i++)
     {
        $row = mysql_fetch_array($res);
                echo '<div class="testimonial">';
                echo '  <ul>';
                echo '    <li>'.$row['field'].'</li>';
                echo '  </ul>';
                echo '</div>';

        if ($i%3 == 0) echo '</div><div class="testimonial-row">';
     }  
   echo '</div>';

您不应使用 id="testimonial-row" 或 id="testimonial"。而是使用 class="testimonial-row"。

   echo '<div class="testimonial-row">';
    for ($i=1;$i<=$mysql_num_rows($res);$i++)
     {
        $row = mysql_fetch_array($res);
                echo '<div class="testimonial">';
                echo '  <ul>';
                echo '    <li>'.$row['field'].'</li>';
                echo '  </ul>';
                echo '</div>';

        if ($i%3 == 0) echo '</div><div class="testimonial-row">';
     }  
   echo '</div>';

You should not use id="testimonial-row" or id="testimonial". Instead use class="testimonial-row".

三生殊途 2024-10-01 15:02:02

这是一些代码

$count = db_select_count...
$lastGroupCount = $count % 3;
$fullGroupCount = $count - lastGroupCount;
for ($i=0; $i<$fullGroupCount; $i++)
{
    output_testimonial_row_html(maybe_pass_an_id);
    for ($j=0; $j<3; $j++)
    {
        output_testimonial_html($count[$i*3+$j]);
    }
    close_div();
}

if ($lastGroupCount > 0)
{
    output_testimonial_row_html(maybe_pass_an_id)
    for ($j=0; $j<$lastGroupCount; $j++)
    {
        output_testimonial_html($count[$fullGroupCount*3+$j]);
    }
    close_div();
}

Here's some code

$count = db_select_count...
$lastGroupCount = $count % 3;
$fullGroupCount = $count - lastGroupCount;
for ($i=0; $i<$fullGroupCount; $i++)
{
    output_testimonial_row_html(maybe_pass_an_id);
    for ($j=0; $j<3; $j++)
    {
        output_testimonial_html($count[$i*3+$j]);
    }
    close_div();
}

if ($lastGroupCount > 0)
{
    output_testimonial_row_html(maybe_pass_an_id)
    for ($j=0; $j<$lastGroupCount; $j++)
    {
        output_testimonial_html($count[$fullGroupCount*3+$j]);
    }
    close_div();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文