我对php中的while循环很困惑。我需要从sql数据库中检索数据并显示onclick按钮。但我不知道如何处理while循环。我希望我在这里犯了一个错误。提前致谢
<p>Show page <span onclick="show('Page1');">1</span>, <span onclick="show('Page2');">2</span>, <span onclick="show('Page3');">3</span>.
</p>
<table width="100%" border="1" cellpadding="10" cellspacing="0" style="font-size:11px; font-family:verdana;" >
<thead>
<tr><td colspan ="6"><b>TITLE</b></td></tr>
<tr>
<th>Site ID</th>
<th>Site Name</th>
<th>Site Address</th>
<th>Project Type</th>
<th>Expected Date</th>
<th>Number of Days Left</th>
</tr>
</thead>
<div id="Page1" class="page" style="">
<div id="quotation">
<?php
while($fiberexcel = mysqli_fetch_assoc($records)):
$A1=$fiberexcel['SiteID0']; //1
$A2=$fiberexcel['SiteName1']; //2
$A3=$fiberexcel['SiteAddress2']; //3
$A4=$fiberexcel['ProjectType3']; //4
$A13=$fiberexcel['ExpectDateABC'];
date_default_timezone_get('Asia/Colomb');
$A13=$fiberexcel['ExpectDateABC'];
$today= date('Y-m-d');
if (date('Y-m-d') <= $A13)
{
echo "<tr>";
echo "<td>" .$fiberexcel['SiteID0'] ." </td>";
echo "<td>" .$fiberexcel['SiteName1'] ." </td>";
echo "<td>" .$fiberexcel['SiteAddress2'] ." </td>";
echo "<td>" .$fiberexcel['ProjectType3'] ." </td>";
echo "<td>" .$fiberexcel['ExpectDateABC'] ." </td>";
echo "<td>";
$years="";
$months="";
$days="";
$datetime1 = new DateTime($today);
$datetime2 = new DateTime($A13);
$interval = $datetime2->diff($datetime1);
$years=$interval->format('%Y');
$months=$interval->format('%m');
$days=$interval->format('%d');
echo $years." Years " .$months. " Months " . $days. " Days " . "</td>";
echo "</tr>";
}
?>
<?php endwhile?>
</table>
</div></div>
<div id="Page2" class="page" style="display:none">
<div id="quotation">
<tr><td colspan ="6"><b>TITLE</b></td></tr>
<?php
while($fiberexcel = mysqli_fetch_assoc($records)):
$A1=$fiberexcel['SiteID0']; //1
$A2=$fiberexcel['SiteName1']; //2
$A3=$fiberexcel['SiteAddress2']; //3
$A4=$fiberexcel['ProjectType3']; //4
$A15=$fiberexcel['ExpectDateABC'];
date_default_timezone_get('Asia/Colomb');
$A15=$fiberexcel['ExpectDateABC'];
$today= date('Y-m-d');
if (date('Y-m-d') <= $A15)
{
echo "<tr>";
echo "<td>" .$fiberexcel['SiteID0'] ." </td>";
echo "<td>" .$fiberexcel['SiteName1'] ." </td>";
echo "<td>" .$fiberexcel['SiteAddress2'] ." </td>";
echo "<td>" .$fiberexcel['ProjectType3'] ." </td>";
echo "<td>" .$fiberexcel['ExpectDateABC'] ." </td>";
echo "<td>";
$years="";
$months="";
$days="";
$datetime1 = new DateTime($today);
$datetime2 = new DateTime($A15);
$interval = $datetime2->diff($datetime1);
$years=$interval->format('%Y');
$months=$interval->format('%m');
$days=$interval->format('%d');
echo $years." Years " .$months. " Months " . $days. " Days " . "</td>";
echo "</tr>";
}
?>
<?php endwhile?>
</table>
</div></div>
</div>
<div id="Page3" class="page" style="display:none">
Next table & so on
</div>
答案 0 :(得分:0)
点击后,您可以在javascript中向该php发出一些xhr请求并从中获取响应,然后您可以将数据呈现给dom。