Reputation: 335
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
Upvotes: 2
Views: 179