我是这里的 MySQL 初学者。我正在寻找一个类似于实际的行和列板的表格,从 A1 到 C22(我也将这些坐标称为)。MySQL 脚本的结果类似于如下所示的排列(我实际上想在此处绘制一个表格,每个孔占据一个单元格以进行说明,但可以这样做):
A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A20 A21 A22
B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B16 B17 B18 B19 B20 B21 B22
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C16 C17 C18 C19 C20 C21 C22
在实际数据库中,存在A1到A22和C1到C22的数据,因此必须如上表所示以斜体形式显示。我试图创建一个包含 A1 到 C22 的数组(我将其称为 $arr),并将该数组与包含 A1 到 A22 和 C1 到 C22 的数据库的另一个数组进行比较(我将其称为 $result)。我用了array_intersect
在 $arr 的元素和数据库中的数组之间找到一个交集。如果存在,则 $arr 中的该元素必须以斜体显示。
这就是我的脚本的运行方式。我知道这是垃圾,但我试过了..
<?php
$con = mysql_connect("localhost","root","1234");
mysql_select_db("inhouse_collection", $con) or die (mysql_error());
$result = mysql_query("SELECT * from ft7 ORDER BY SUBSTRING(Plate_Loc, 1, 1) ,SUBSTRING(Plate_Loc, 2)+0");
$arr=array("A1","A2","A3","A4","A5","A6","A7","A8","A9","A10","A11","A12","A13","A14","A15","A16","A17","A18","A19","A20","A21","A22","B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11","B12","B13","B14","B15","B16","B17","B18","B19","B20","B21","B22","C1","C2","C3","C4","C5","C6","C7","C8","C9","C10","C11","C12","C13","C14","C15","C16","C17","C18","C19","C20","C21","C22");
echo "<table border='1'>";
echo "<tr>";
$z= 0;
for( $i=0; $arr[$z++]; $i = ($i+1)) {
if( array_intersect( $arr[$z-1], $result(Plate_Loc)) {
echo "<td><i>". $arr[$z-1] ."</i></td>";
}
else
echo "<td>" . $arr[$z-1] . "</td>";
if($i == 21)
echo "</tr><tr>";
}
echo "</tr>";
echo "</table>";
?>
</div>
</html>