<tfoot id='AohiG'></tfoot>

      1. <legend id='AohiG'><style id='AohiG'><dir id='AohiG'><q id='AohiG'></q></dir></style></legend>
          <bdo id='AohiG'></bdo><ul id='AohiG'></ul>

        <small id='AohiG'></small><noframes id='AohiG'>

        <i id='AohiG'><tr id='AohiG'><dt id='AohiG'><q id='AohiG'><span id='AohiG'><b id='AohiG'><form id='AohiG'><ins id='AohiG'></ins><ul id='AohiG'></ul><sub id='AohiG'></sub></form><legend id='AohiG'></legend><bdo id='AohiG'><pre id='AohiG'><center id='AohiG'></center></pre></bdo></b><th id='AohiG'></th></span></q></dt></tr></i><div id='AohiG'><tfoot id='AohiG'></tfoot><dl id='AohiG'><fieldset id='AohiG'></fieldset></dl></div>
      2. 每行仅显示 3 个 foreach 结果

        时间:2023-09-23
          <bdo id='KGxPE'></bdo><ul id='KGxPE'></ul>

                <tbody id='KGxPE'></tbody>
              <legend id='KGxPE'><style id='KGxPE'><dir id='KGxPE'><q id='KGxPE'></q></dir></style></legend>
              1. <i id='KGxPE'><tr id='KGxPE'><dt id='KGxPE'><q id='KGxPE'><span id='KGxPE'><b id='KGxPE'><form id='KGxPE'><ins id='KGxPE'></ins><ul id='KGxPE'></ul><sub id='KGxPE'></sub></form><legend id='KGxPE'></legend><bdo id='KGxPE'><pre id='KGxPE'><center id='KGxPE'></center></pre></bdo></b><th id='KGxPE'></th></span></q></dt></tr></i><div id='KGxPE'><tfoot id='KGxPE'></tfoot><dl id='KGxPE'><fieldset id='KGxPE'></fieldset></dl></div>
                <tfoot id='KGxPE'></tfoot>

                <small id='KGxPE'></small><noframes id='KGxPE'>

                  本文介绍了每行仅显示 3 个 foreach 结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有如下脚本

                  $output="<table class='products'><tr>"; 
                  while($info = mysql_fetch_array( $data )) { 
                      //Outputs the image and other data
                      $output.= "<td>
                      <img src=http://localhost/zack/sqlphotostore/images/"   .$info['photo'] ." width=323px ></img> 
                      <b>Name:</b> ".$info['name'] . "
                      <b>Email:</b> ".$info['email'] . " 
                      <b>Phone:</b> ".$info['phone'] . "</td> "; 
                  }
                  $output.="<tr></table>";
                  print $output;
                  ?>
                  

                  它以长水平线显示所有结果我如何打破结果以便它们显示3 次后在新行中.

                  it shows all results in long horizontal line how do i break the results so that they show in new row after 3 count.

                  推荐答案

                  添加一个计数器并在每次达到 3 的倍数时开始新行.

                  Add a counter and start a new row every time it reaches a multiple of 3.

                  $counter = 0;
                  while($info = mysql_fetch_array($data)) {
                     if ($counter++ % 3 == 0) {
                         if ($counter > 0) {
                             $output .= "</tr>";
                         }
                         $output .= "<tr>";
                     }
                     // stuff
                  }
                  if ($counter > 0) {
                      $output .= "</tr>";
                  }
                  
                  $output .= "</table>";
                  

                  请注意:它可能无法回答您的问题,但您应该停止使用 mysql_* 函数.它们正在被弃用.而是使用 PDO(自 PHP 5.1 起支持)或 mysqli(自 PHP 4.1 起支持).如果您不确定使用哪个,阅读这篇文章.

                  Please note: It may not help answer your question, but you should stop using mysql_* functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this article.

                  这篇关于每行仅显示 3 个 foreach 结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:$k => 是什么意思?$v in foreach($ex as $k=>$v) 是什 下一篇:带有 HTML 的 PHP 简单 foreach 循环

                  相关文章

                  最新文章

                  <tfoot id='5ov1c'></tfoot>
                  • <bdo id='5ov1c'></bdo><ul id='5ov1c'></ul>
                  <i id='5ov1c'><tr id='5ov1c'><dt id='5ov1c'><q id='5ov1c'><span id='5ov1c'><b id='5ov1c'><form id='5ov1c'><ins id='5ov1c'></ins><ul id='5ov1c'></ul><sub id='5ov1c'></sub></form><legend id='5ov1c'></legend><bdo id='5ov1c'><pre id='5ov1c'><center id='5ov1c'></center></pre></bdo></b><th id='5ov1c'></th></span></q></dt></tr></i><div id='5ov1c'><tfoot id='5ov1c'></tfoot><dl id='5ov1c'><fieldset id='5ov1c'></fieldset></dl></div>

                    <legend id='5ov1c'><style id='5ov1c'><dir id='5ov1c'><q id='5ov1c'></q></dir></style></legend>

                    <small id='5ov1c'></small><noframes id='5ov1c'>