0

我有两列信息相似:

第 1 列 = 第 1 项、第 3 项、第 5 项 第 3 列 = 第 3 项、第 5 项、第 8 项

我想显示两列中每个项目的总数。

我有这个:


$sql = mysql_query("SELECT FirstTypeID, SecondTypeID, ThirdTypeID, DesignID, COUNT(DesignID) FROM designs WHERE Approved = '1' GROUP BY FirstTypeID, SecondTypeID, ThirdTypeID");
while ($row = mysql_fetch_array($sql)) {
    $DesignID = stripslashes($row['DesignID']);
    $FirstTypeID = stripslashes($row['FirstTypeID']);
    $SecondTypeID = stripslashes($row['SecondTypeID']);
    $ThirdTypeID = stripslashes($row['ThirdTypeID']);
    $Total = stripslashes($row['COUNT(DesignID)']);
}

$result2 = mysql_query("SELECT * FROM types WHERE TypeID = '$FirstTypeID' OR TypeID = '$SecondTypeID' OR TypeID = '$ThirdTypeID'");
while ($row2 = mysql_fetch_array($result2)) {
    echo "<li><a href='index_type.php?TypeID=".$row2{'TypeID'}."'>".$row2{'TypeName'}." (" . $Total . ")</a></li>";
}

但我没有得到我想要的结果,它只给我一列的结果。

4

1 回答 1

1

我不确定这是否是你所要求的,但它就在这里

$typesIDs = array(type0 => "", type1 => "", type2 => ""...);

foreach($typesID as $index=>$value){
   $query = "SELECT COUNT(*) AS total FROM designs COLUMN1 = ".$index." OR COLUMN2 = ".$index;
   $sql = mysql_query($query);
   $row = mysql_fetch_array($sql);
   array[$index] => $row["total"]
}
于 2013-08-28T19:05:03.563 回答