Forum Moderators: coopster

Message Too Old, No Replies

Display Image In Loop Where Expired

         

oceanwave

8:29 pm on Aug 4, 2008 (gmt 0)

10+ Year Member



Hi,

I've simplified my loop here:
_____

$result=mysql_query("SELECT * FROM items WHERE userid ='$userid' AND lastname = '$lastname'");

while($row=mysql_fetch_assoc($result)){

echo "ID : $row[id]       ";
echo "Expires On (Y/M/D) : $row[date_expired]     ";
_____

1. I want to echo the image renew.jpg only where date_expired is less than today' date. In otherwords, the renew button will only show in the loop where the item has expired.

2. I then want the renew.jpg button, if clicked, to add 3 months from today's date to the item's date_expired in the "items" database.

How would I go about doing this inside the loop?

Thank You!

ag_47

3:29 am on Aug 5, 2008 (gmt 0)

10+ Year Member



How is date stored inside the database?
Try getting the current time(), then compare what the day (weekday or day of month) values.

oceanwave

4:16 am on Aug 5, 2008 (gmt 0)

10+ Year Member



Hi ag_47,

Thanks for responding. date_expired is stored like 0000-00-00 (year-month-day). For example: 2008-09-28

I am having trouble figuring out how to echo the image in the loop, only when the item is expired.

ag_47

5:25 am on Aug 5, 2008 (gmt 0)

10+ Year Member



Hmm, this proved to be more challenging than I expected :P
But it's all in knowing what available to you, and PHP has tons of nice methods. I think I found just what you need, try this:

..
$expday = strtotime( $row['date_expired'] ); //will return number of seconds, like time()
$today = time();
if( $today < $expday ) {

echo "<img src='renew.jpg' onclick=' .. ' />"; //whatever else you need
}
..

dreamcatcher

7:03 am on Aug 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do a simple date comparison:

if (date("Y-m-d")>$row['date_expired']) {
// expired
}

Adding 3 months on to date via strtotime:

$newdate = date('Y-m-d', strtotime("+3 months", strtotime($row['date_expired'])));

dc

oceanwave

5:50 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



Thank you both for answering. I am now able to get the image next to the expired items. I am using the image as a link to another page that will update the database. However, it is not updating the database properly. I checked the variables that are being passed usintg echo, and found that when date_expired = 2007-11-11, the newdate = 1970-03-03.

What I would like to do is have the newdate equal today plus 90 days. Looking forward to your reply.

oceanwave

6:16 pm on Aug 5, 2008 (gmt 0)

10+ Year Member



This seems to work.

$newdate = date('Y-m-d',strtotime('+90day'));