<legend id='Zemhb'><style id='Zemhb'><dir id='Zemhb'><q id='Zemhb'></q></dir></style></legend>

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

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

      1. <tfoot id='Zemhb'></tfoot>
      2. 优化foreach中的while和SQL

        时间:2023-09-20

            • <bdo id='81r3D'></bdo><ul id='81r3D'></ul>

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

                  <tbody id='81r3D'></tbody>
                  <tfoot id='81r3D'></tfoot>

                  <small id='81r3D'></small><noframes id='81r3D'>

                  <legend id='81r3D'><style id='81r3D'><dir id='81r3D'><q id='81r3D'></q></dir></style></legend>

                  本文介绍了优化foreach中的while和SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的代码:

                  $text = '12-name-y-86';
                  $array = explode('-',$text);
                  foreach($array as $value) {
                      $sql = mysql_query("SELECT * FROM `table` WHERE `pid`='$value' ORDER BY `id` LIMIT 3");
                      echo '***'.$value.'***';
                      echo '<br />';    
                      while($row = mysql_fetch_array($sql)) {
                          echo $row['title'];
                          echo '<br />';
                      }
                      echo '<br /><br />';
                  }
                  

                  打印:

                  12

                  标题1

                  标题2

                  标题3

                  姓名

                  ti1

                  ti2

                  ti3

                  t1

                  t2

                  tle3

                  86

                  mytitle1

                  mytitle2

                  mytitle3

                  此代码可以完全购买 $text 中的更多值,服务器已关闭!

                  This code work full buy for more values in $text , server has down !

                  推荐答案

                  尝试在一个查询中选择所有记录,如下所示:

                  Try to select all records in just one query, like this:

                  $text = '12-name-y-86';
                  $array = explode('-', $text);
                  $array = "'" . implode(',', $array) . "'";
                  $sql = mysql_query("SELECT * FROM `table` WHERE `pid` IN (' . $array . ') ORDER BY `id` LIMIT 3");
                  while($row = mysql_fetch_array($sql)) {
                      echo $row['title'];
                      echo '<br />';
                  }
                  echo '<br /><br />';
                  

                  这篇关于优化foreach中的while和SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PHP - While/Else 错误? 下一篇:如何为 PHP 安装 ffmpeg

                  相关文章

                  最新文章

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

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

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