PHP:一个查询中有两个表

时间:2013-10-07 04:54:30

标签: php mysql sql checkbox

我有两个不同的查询如下....

以下是我的网络和构建名称列表。

Network            BuildingName
Mass and Mobile    Araneta
Mass and Mobile    Home Sweet
Hotels             Atrium Hotels

实施例: 在我的组合框中,显示在那里的网络为"Mass and Mobile" and "Hotels",之后当我选择Mass and Mobile时,它将显示带有CHECKBOX的"Araneta""Home Sweet"。所以这是我的计划。

 echo "<div><input type='checkbox' class='checkall'> Check all</div>";
    $section = mysql_query("SELECT fldBldgName FROM tblbuilding where fldNetname = '$get_ID' ORDER BY fldBldgName");
    while ($row = mysql_fetch_array($section))
    {
        echo "<tr><td>";
        echo "<div><input id='playbldg' type='checkbox'  name='play[]' class='chk_boxes1' value='" . $row['fldBldgName']."'>";
        echo $row['fldBldgName'];"</div>";
        echo "</td></tr><br/>";
    }
    echo "<br/>";
    echo "<br/>";
    echo "<input type='submit' name='save' value='Add'  onClick='checkFields()'>";

这是我的另一个表的代码...将其命名为tbldata [此字段用于保存信息]

我的数据库中tbldata的示例列表。我们可以看到我已经有一个总持续时间字段...

fldNetname          fldBldgName       fldTotalDuration
Mass and Mobile     Araneta            08:00:00
Mass and Mobile     Home Sweet         00:25:00

在Mass and Mobile中,最长总持续时间是08:00:00,因为我们可以看到Araneta的建筑已经满了,但Home Sweet尚未满了....

我打算这样做,如果Araneta的建筑名称已满,则没有复选框,但当它低于08:00:00时,复选框将显示....

我想要做的输出示例:

Araneta - 08:00:00

Home Sweet - 00:25:00

输出:assuming the "[]" is the checkbox

   Araneta
[] Home Sweet
[] Sugar Free
[] Google

我如何实现?

1 个答案:

答案 0 :(得分:0)

希望这适合你

    echo "<div><input type='checkbox' class='checkall'> Check all</div>";
    $section = mysql_query("SELECT fldBldgName,if(fldTotalDuration<'08:00:00','show','notshow') as status FROM tblbuilding where fldNetname = '$get_ID' ORDER BY fldBldgName");
    while ($row = mysql_fetch_array($section))
    {
        echo "<tr><td>";
        if($row['status']=='show'){
            echo "<div><input id='playbldg' type='checkbox'  name='play[]' class='chk_boxes1' value='" . $row['fldBldgName']."'>";
        }
        else{
            echo "<div>";
        }       
        echo $row['fldBldgName'];"</div>";
        echo "</td></tr><br/>";
    }
    echo "<br/>";
    echo "<br/>";
    echo "<input type='submit' name='save' value='Add'  onClick='checkFields()'>";