繁体   English   中英

从表中获取所有值并计算具有特定单词的所有单词

[英]Get all the values from the table and Count all the words with specific Word

这是我的代码

<?php

        for ($x = 0; $x <= $n; $x++)
        {
            //Counting of rows
            $countrow = get_rows($getvids);
 
            
            if($offline == "Offline")
             {


              $apsys = "APSYS";
              $offlined = "";

              if ($getvids == $apsys ||  $getvids == $offlined )
              {

              echo "<tr>
              <th>$x</th>
                <th>$accntid[$x]</th>
                <th>$fname[$x]</th>
                <th>$lname[$x]</th>
                <th>$vid[$x]</th>
                <th>$vplatenum[$x]</th>
                <th>$imei[$x]</th>
               <th>$datas[1]</th>
                <th>$datas[0]</th>
                <th>$offline</th>";
                echo "<th>$getvids</th>";
                echo "<th><button type = 'button' class = 'btn btn-success viewbtn'> View Troubleshoot Report History</button></th>";
                echo "</tr> "; 
                
                echo "total number of Rows:";
                echo str_word_count($countrow);

             }

             else
             {
              }
             }
            else
             {
                
             }  

                   
        }


         ?>

这是我的功能

<?php
function get_rows($getrowscount)
{
  require ('db_connection.php');

 $getrowscounts = $getrowscount;
 //echo $getrowscounts;

 return $getrowscounts;

}
//get_rows(); // call the function
?>

该表显示了两行,其值为 = "APSYS" 我想计算行数并显示如下输出:行总数:2

但我只能得到的输出是这样的:总行数:1 总行数:1 总行数:0

有人可以帮助我吗,我对用什么来计算行数有点困惑? 谢谢。

这个怎么样? 这是否满足您的要求?

<?php
        $countrow = 0;
        for ($x = 0; $x <= $n; $x++)
        {
            //Counting of rows
            $countrow = $countrow + get_rows($getvids);
            if($offline == "Offline")
             {
                 //omitted
             }
             else
             {
              }
             }
        }
        echo "total number of Rows:";
        echo str_word_count($countrow);

?>

如果您在从数据库中获取数据后尝试对它们进行计数,请尝试编写 SQL 查询而不是您当前的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM