我有一个问题是在一个HTML表中列出来自两个MySQL表的记录。 在MySQL中我有:表'字段'与'ForUser','ForCategory','FieldName'和表'内容'与'ForUser','ForCategory','ForField','FieldContent'。现在我想将FieldName列为HTML Table Head,将FieldContent列为HTML Table Body。 我列出了表头:
<?php
$conn = new mysqli($SERVERNAME, $USERNAME, $PASSWORD, $DBNAME);
if ($conn->connect_error) {
die("Greska: " . $conn->connect_error);
}
$sql = "SELECT FieldName FROM Fields WHERE ForUser = '$User_Check' AND ForCategory = '$CategoryName'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='table table-bordered'><thead><tr>";
while($row = $result->fetch_assoc()) {
echo "<th>".$row["FieldName"]."</th>";
}
echo "</tr></thead>";
}
else {
echo "<div style='margin-top: 18px;' class='alert alert-danger'><b>$lang[MANAGE_CATEGORY_ALERT]</b></div>";
}
echo "</table>";
$conn->close();
?>
现在我不知道如何为Table Head中的每个FieldName列出FieldContent, 分别我不知道如何在
中获得字段名称$sql = "SELECT FieldContent FROM Contnt WHERE ForUser = '$User_Check' AND ForCategory = '$CategoryName' AND ForField = '$ForField'";
作为数组,然后执行:
$result = $conn->query($sql);
对于每个$ SQL,显示HTML Table Body中与'ForField'相关的所有数据。
罐