php - Group By 2 Columns with similar info to link with a 2nd table -
i have two columns similar info:
column 1 = item 1, item 3, item 5 column 3 = item 3, item 5, item 8
i want display how many of each item in total both columns.
i have this:
$sql = mysql_query("select firsttypeid, secondtypeid, thirdtypeid, designid, count(designid) designs approved = '1' group 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 * types 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>"; }
but i'm not getting result want, it's giving me results 1 column.
i'm not sure if asking here is
$typesids = array(type0 => "", type1 => "", type2 => ""...); foreach($typesid $index=>$value){ $query = "select count(*) total designs column1 = ".$index." or column2 = ".$index; $sql = mysql_query($query); $row = mysql_fetch_array($sql); array[$index] => $row["total"] }
Comments
Post a Comment