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.

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>';
    }
}

?>

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.