Mysqli从不同的表中选择数据并在一个FOR循环中显示

时间:2015-07-08 08:46:12

标签: php mysql mysqli

我的第一个问题是:

$query3 ="SELECT  * FROM leave_status WHERE  SchoolID='$storedValue'  And StudentRegID='$REGID' and Approvestatus ='Pending' order by From_date desc ";
$res3=mysqli_query($mysqli, $query3);
echo "<select id=\"ddPurpose\">";
for($i=0; $row=mysqli_fetch_assoc($res3); $i++) {

    $slno = $row['slno'];

    $dat5 = $row['Till_date'];
    $dat6 = $row['From_date'];
    $From_date=date("Y-m-d", strtotime($dat6));
    $Till_date=date("Y-m-d", strtotime($dat5));

    echo "<div class=\"panel\" title=\"Modify Leave\" id=\"".$slno."\" data-footer=\"none\">
        <input type='date' id='fromdate[".$i."] ' value='".$From_date."'></input>
        <input type='date' id='tilldate[".$i."] ' value='".$Till_date."'></input>
echo "<option value=\"".$row[LeavePurpose]."\">".$row[LeavePurpose]."</option>";
        </div>";

}
echo "</select>";

我的第二个问题

$query="SELECT * FROM leave_table  WHERE  Schoolid='$selname'";
$data=mysqli_query($mysqli,$query)or die(mysqli_error());
echo "<select id=\"ddPurpose\">";
while($row=mysqli_fetch_array($data)){
echo "<option value=\"".$row[2]."\">".$row[2]."</option>";
} 
echo "</select>";

我想合并第一个和第二个查询并在第一个查询<div>中打印输出,这是

    echo "<div class=\"panel\" title=\"Modify Leave\" id=\"".$slno."\" data-footer=\"none\">
        <input type='date' id='fromdate[".$i."] ' value='".$From_date."'></input>
        <input type='date' id='tilldate[".$i."] ' value='".$Till_date."'></input>
<option value=\"".$row[2]."\">".$row[2]."</option>
        </div>";

合并查询后,我想确定第二个查询也像第一个查询一样重复相同的次数。

仅供参考,第二个查询是从表

下拉列表
    Slno,  Schoolid  , LeavePurpose, 
    '1',  'FT001',   'Leave Type'
    '2',  'FT001',   'Hospitalzation leave'
    '3',  'FT001',   'Planned Leave'
    '4',  'FT001',   'Military Leave'
    '5',  'FT001',   'Study Leave'
    '6',  'FT001',   'Sick Leave'

0 个答案:

没有答案