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

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

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

      • <bdo id='S7Ucj'></bdo><ul id='S7Ucj'></ul>
      <tfoot id='S7Ucj'></tfoot>
      1. mysql 计入 PHP 变量

        时间:2023-07-15

            <tfoot id='RYQ2Q'></tfoot>

                <tbody id='RYQ2Q'></tbody>

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

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

                • <bdo id='RYQ2Q'></bdo><ul id='RYQ2Q'></ul>
                • 本文介绍了mysql 计入 PHP 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我们有以下查询:

                  SELECT DISTINCT COUNT(`users_id`) FROM `users_table`;
                  

                  此查询将返回表中的用户数.我需要将此值传递给 PHP 变量.我正在使用这个:

                  this query will return the number of the users from a table. I need to pass this value to a PHP variable. I'm using this:

                  $sql_result = mysql_query($the_query_from_above) or die(mysql_error());
                  
                  if($sql_result)
                  {
                      $nr_of_users = mysql_fetch_array($sql_result);
                  }
                  else
                  {
                      $nr_of_users = 0;
                  }
                  

                  请在您认为必要的地方更正我的代码.

                  please correct my code where you think is necessary.

                  这是最好的方法.您建议如何执行此操作?

                  Which is the best approach. How do you recommend to do this ?

                  推荐答案

                  像这样:

                  // Changed the query - there's no need for DISTINCT
                  // and aliased the count as "num"
                  $data = mysql_query('SELECT COUNT(`users_id`) AS num FROM `users_table`') or die(mysql_error());
                  
                  // A COUNT query will always return 1 row
                  // (unless it fails, in which case we die above)
                  // Use fetch_assoc for a nice associative array - much easier to use
                  $row = mysql_fetch_assoc($data);
                  
                  // Get the number of uses from the array
                  // 'num' is what we aliased the column as above
                  $numUsers = $row['num'];
                  

                  这篇关于mysql 计入 PHP 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP:计算一个 stdClass 对象 下一篇:为什么 count(false) 返回 1?

                  相关文章

                • <tfoot id='o6iwS'></tfoot>

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

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