-1

I am quite confused with the while loop in php. I need to retrieve data from sql database and display onclick button. but I don't know how to do with while loop. I hope I am doing a mistake here. Thanks in advance

<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>
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Sugs
  • 65
  • 1
  • 12
  • @T.J.Crowder Could you please tell me what am I missing here? I am pretty new to this code and I am trying to do a project. Can you help? – Sugs May 11 '17 at 07:39

1 Answers1

0

On click you can make some xhr request in javascript to that php and get the response form it and the you can render the data to dom.

Mr.Throg
  • 925
  • 6
  • 21
  • Can you please explain a little more? What should I do in my code?> – Sugs May 11 '17 at 10:23
  • Check this question for more info http://stackoverflow.com/questions/16834138/javascript-function-post-and-call-php-script – Mr.Throg May 11 '17 at 10:25