dqcd84732 2015-06-01 13:34
浏览 5

从1个HTMl表中的2个MySQL表中选择

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

  • 写回答

1条回答 默认 最新

  • duangu1645 2015-06-01 13:44
    关注

    Please Used MYSQL With Join Query you can get your solution See Link

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line