按具有类似信息的2列分组以链接到第二个表


Group By 2 Columns with similar info to link with a 2nd table

我有两列具有类似信息:

第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>";
}

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

我不确定这是否是你想要的,但这里是

$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"]
}