I have one problem to list records from two MySQL tables in one HTML Table. In MySQL I have: Table 'Fields' with 'ForUser','ForCategory', 'FieldName', and Table 'Content' with 'ForUser','ForCategory', 'ForField', 'FieldContent'. Now i want to list FieldName as HTML Table Head, and FieldContent as HTML Table Body. I has listed Table Head with:
<?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();
?>
Now I don't know how to list FieldContent for each FieldName in Table Head, respectively I Dont know how to get Field Name in
$sql = "SELECT FieldContent FROM Contnt WHERE ForUser = '$User_Check' AND ForCategory = '$CategoryName' AND ForField = '$ForField'";
as array and after that do:
$result = $conn->query($sql);
for each $SQL than display all data in HTML Table Body in regard to their 'ForField'.
Tanks
请使用MYSQL和Join Query,以获得解决方案请参阅链接
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.