gpt4 book ai didi

php - 获取 MySQL 表的每一行的特定列中的元素计数

转载 作者:行者123 更新时间:2023-11-30 00:13:35 25 4
gpt4 key购买 nike

我有一个 MySQL 表,其中有一个数组列,而每个元素均由“,”分隔。我尝试获取所有行的总数 (145)

当我运行以下代码时,我得到的 $index 为 145,这是正确的,但 $totalClasses 为 0。所以显然我遗漏了一些东西。

如果有人指出我的方法中的错误,我将不胜感激!

谢谢

维克

echo "<br><b>Number Classes Entered:</b>";
$SQL="SELECT ExhibitorClasses FROM tblShowEntries WHERE ShowID = $ShowID AND ExhibitorClasses IS NOT NULL AND ExhibitorClasses !=' '";


$result = mysql_query($SQL);
$myClasses = array(); // make a new array

$index = 0;
while($row = mysql_fetch_assoc($result)) // loop to get the count
{
$myClasses[$index] = $row;
$userclasses = count($myClasses[$index]);
$totalclasses = $totalclasses + $userClasses;
$index++;
}

// $userClasses = explode(",", $myClasses);
// $totalclasses = count($myClasses);
echo $index . " " . $totalclasses

最佳答案

$SQL="SELECT ExhibitorClasses FROM tblShowEntries WHERE ShowID = $ShowID AND ExhibitorClasses IS NOT NULL AND ExhibitorClasses !=' '";

您没有连接 var $ShowID 正确的是:

$SQL="SELECT ExhibitorClasses FROM tblShowEntries WHERE ShowID = ".$ShowID." AND ExhibitorClasses IS NOT NULL AND ExhibitorClasses !=' '";

关于php - 获取 MySQL 表的每一行的特定列中的元素计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23848126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com