假设有chemical table
且 4条记录。
chemical_name = c1,c2,c3,c4
我需要以表格形式
来查看输出表格chemical one chemical two
c1 c2
c1 c3
c1 c4
c2 c3
c2 c4
c3 c4
如何在 php 中执行此操作?
向我提出建议
答案 0 :(得分:0)
<?php
echo "<table>";
echo "<thead>";
echo "<tr><th>Chemical One</th><th>Chemical two</th></tr>";
echo "</thead>";
echo "<tbody>";
$chemical=array('c1','c2','c3','c4');
$count_chem=count($chemical);
for ($i=0; $i <= $count_chem; $i++) {
for ($j=$i+1; $j < $count_chem; $j++) {
echo "<tr>";
echo "<td>".$chemical[$i]."</td>";
echo "<td>".$chemical[$j]."</td>";
echo "<tr>";
}
}
echo "</tbody></table>";
?>
尝试这个,让我知道是否有任何问题。
答案 1 :(得分:0)
您可以使用以下查询来获取此输出:
SELECT ch1.chemical, ch2.chemical
FROM chemical ch1
JOIN chemical ch2
ON ch1.chemical < ch2.chemical
ORDER BY ch1.chemical, ch2.chemical ASC