I have problem with my if else statement. I want to show popup box which is a list of late submission.
All i going alright, but there are problem when there are no late submission.
The popup block still appear when it supposed not appear when there are no late submission. I think the problem is the if else closing. I already tried change the code. When I add the closing statement, the popup block dissappear, but the list of late submissions from my MySQL only appear 1 row. Please help me. Thank you in advanced.

Here my code without if else statement:

<?php echo "<div id='hideshow'><div id='fade'></div><div class='popup_block'><div class='popup'><a href='javascript:hideDiv()'><img src='image/icon_close.png' class='cntrl' title='Close' /></a><h3><div class='font'>Pinjaman Melebihi Tarikh Pulang</div></h3>
 <table width='700'>
    <table width='700' class='visi'>         
        <tr><th colspan='5'></th></tr>
          <td width='95' bgcolor='#69F'><center><strong><font face='arial' color='white'>NOMBOR PEKERJA</font></strong></center></td>
          <td width='101' bgcolor='#69F'><center><strong><font face='arial' color='white'> NAMA PEKERJA</font></strong></center></td>
          <td width='107' bgcolor='#69F'><center><strong><font face='arial' color='white'> NO. TRACK</font></strong></center></td>
          <td width='144' bgcolor='#69F'><center><strong><font face='arial' color='white'>NO. RUJUKAN</font></strong></center></td>
          <td width='89' bgcolor='#69F'><center><strong><font face='arial' color='white'><center>TARIKH PULANG</center></font></strong></center></td>
          <td width='49' bgcolor='#69F'><center><strong><font face='arial' color='white'><center>LIHAT</center></font></strong></center></td>

        $date = date("d/m/Y");
        $query = "SELECT * FROM  pinjaman WHERE statusPinjaman = 'Pinjam' AND NOW() >= tarikhPulang";
        $result = mysql_query($query, $conn);

        while($row = mysql_fetch_array($result)){
        $noPinjaman = $row["noPinjaman"];
        $ID = $row["ID"];
        $noRujukan = $row["noRujukan"];
        $tarikhPulang = $row["tarikhPulang"];
        $tajuk = $row["tajuk"];
        $namaStaff = $row["namaStaff"];
        $noTrack = $row["noTrack"];



    echo "<table width ='700'>
             <td width='95' bgcolor='#white'><center><font color='#0033CC' face='arial' size='2'>".$row['ID']."</font></center></td>
             <td width='101' bgcolor='#white'><font color='#0033CC' face='arial' size='2'>".$row['namaStaff']."</font></td> 
             <td width='107' bgcolor='#white'><font color='#0033CC' face='arial' size='2'>".$row['noTrack']."</font></td>
             <td width='144' bgcolor='#white'><font color='#0033CC' face='arial' size='2'>".$row['noRujukan']."</font></td>
             <td width='89' bgcolor='#white'><center><font color='#0033CC' face='arial' size='2'>".$row['tarikhPulang']."</font></center></td>
             <td width='49' bgcolor='#white'><center><a href='lihatPinjaman.php?noPinjaman=".$row['noPinjaman']."'>LIHAT</a></center></td>


Here my if else statement:

$date = date("d/m/Y");

if (strtotime($row['tarikhPulang']) < $date)
  ////code above


  echo "";


Edited by nurul_1

3 Years
Discussion Span
Last Post by virtualsky

I always compare dates in mysql query insteal of in php. I suggest you to do same. I feel handling dates is little complicated in php specially for comparision.

$query = "SELECT *  FROM  pinjaman  WHERE statusPinjaman = 'Pinjam' AND NOW() >= tarikhPulang";

I guess you do not need any if else statment, becuase you are already getting records where now()> tarikhpulang

But still you want to get both kind of records, then you can add extra column in your query, and remove part of where clause

$query = "SELECT a.*, case when now>=tarikhpulang then 'Yes' else 'No' end date_expired  FROM  pinjaman a  WHERE statusPinjaman = 'Pinjam' ";

then use new column in if else statment

if ($row['date_expired']=='Yes')

Edited by urtrivedi


Thank you for your reply. I will try your suggestion.

Yes, you are right, I do not need if else statement for getting the record. I need the if else statement for the popup block show when there are late submission and when there are no submission, the popup block not show.

From my php code above, I already get the records from mysql. But when I insert it in the if else statement, there are problem like I explained above.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.