0

Hello, i'm kindly in a trouble. I was a newbie here and also not expert in php. So, my question maybe too easy and my english may broken. If you know the answer, tell me, I really need help. My question was about expiry date warning. I wish to make the expired date give a warning to the user, a week before. So, I try to make this code, still not working. Yeah, I know it is too simple, but I hope anyone can help me here. Thanks a lot. Here is my code.

<?php
$dtwarning = mysqli_prepare($db,"SELECT tarikh_tamat FROM spoc_pma2012 ORDER BY bil");
$dtwarning->execute();
$currentDate = date("Y-m-d");
    while($dtwarning = row($tarikh_tamat)-7){
        if($currentDate=$dtwarning){
        echo '<div class="error">
             <p>Warning</p>
         </div>';
         }
         }

?>

Hope anyone can help me. :)
Sorry for disturbing all of you.

2
Contributors
3
Replies
30
Views
4 Years
Discussion Span
Last Post by simplypixie
1

You can actually do this in your query instead of PHP

<?php
$dtwarning = mysqli_prepare($db,"SELECT DATEDIFF(tarikh_tamat, NOW()) AS date_diff FROM spoc_pma2012 ORDER BY bil");
$dtwarning->execute();
$results = $dtwarning->fetch_all();
foreach ($results as $row) {
    if ($row['date_diff'] <= 7) {
        echo '<div class="error">
             <p>Warning</p>
         </div>';
    }
}

?>
0

I've already changed the code the way you taught me but I have an error :
Fatal error: Call to a member function execute() on a non-object

$dtwarning->execute();

Sorry again trouble you

0

I have just noticed that you are trying to order by bil but you are not selecting bil in your query. Try the code without the order by first and see if that works.

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.