CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Stuck on an IF statement (http://www.codingforums.com/showthread.php?t=283717)

TonySweeps 12-07-2012 03:27 AM

Stuck on an IF statement
 
Background: I have a database of sweepstakes. I am trying to get a "new" image to appear in the listing when the startdate is within 7 days of the current date.

I am not able to get it to appear. I annotated the new part below. Any ideas? I'm stuck on it.

Here is most of the code...


PHP Code:

$sql "SELECT startdate,sponsor,url,prize,enddate,prizevalue,category,frequency,country,AB,BC,MB,NB,NL,NT,NS,NU,ONT,PE,QC,SK,YT FROM SweepDirectory WHERE category = 'Cash' and status = 'Y' and enddate > DATE_SUB(CURDATE(), INTERVAL 1 DAY) ORDER BY enddate ASC ";

$result mysql_query($sql$conn);
$nummysql_num_rows($result);

mysql_close();


 
$num;

  if(
$num == 0) {
    echo 
'image file';
    }

$i=0;
while (
$i $num) {


$startdate=mysql_result($result,$i,"startdate");
$sponsor=mysql_result($result,$i,"sponsor");
$category=mysql_result($result,$i,"category");
$prizevalue=mysql_result($result,$i,"prizevalue");
$prize=mysql_result($result,$i,"prize");
$url=mysql_result($result,$i,"url");
$enddate=mysql_result($result,$i,"enddate");
$frequency=mysql_result($result,$i,"frequency");
$country=mysql_result($result,$i,"country");
$AB=mysql_result($result,$i,"AB");
$BC=mysql_result($result,$i,"BC");
$MB=mysql_result($result,$i,"MB");
$NB=mysql_result($result,$i,"NB");
$NL=mysql_result($result,$i,"NL");
$NT=mysql_result($result,$i,"NT");
$NS=mysql_result($result,$i,"NS");
$NU=mysql_result($result,$i,"NU");
$NB=mysql_result($result,$i,"ONT");
$PE=mysql_result($result,$i,"PE");
$QC=mysql_result($result,$i,"QC");
$SK=mysql_result($result,$i,"SK");
$YT=mysql_result($result,$i,"YT");


//this is the part I am working on.

     
$startdate 'DATE_SUB(now(), INTERVAL 7 DAY)';

     if ( 
$startdate 'DATE_SUB(now(), INTERVAL 7 DAY)'  ) {
    echo 
"<img src='images/newii.gif' border='0'>";
     }
     echo 
"";


echo 

<font size=3><b>$sponsor</b></font><br />
<a href=\"$url\" target=\"_blank\">"
;
echo 
substr($prize0150); echo "</a><br /> 
<b>Prize Value:</b> \$$prizevalue &nbsp;&nbsp;&nbsp;&nbsp; <b>End Date: </b> $enddate &nbsp;&nbsp;&nbsp;&nbsp; <b>Frequency:</b> $frequency <br />
<b>Country:</b> $country&nbsp;&nbsp;&nbsp;&nbsp; <b>Province:</b> $AB $BC $MB $NB $NL $NT $NS $NU $ONT $PE $QC $SK $YT<br />
<a href=\"$url\" target=\"_blank\">"
; echo substr($url050); echo " </a>
<hr><br>"
;

$i++;
}
 
?> 


abduraooft 12-07-2012 09:52 AM

Quote:

mysql_close();
You may omit that line from your code since mysql will automatically close the connection when the execution completes Or you need to move that line to the very end of your PHP code.

>ssp-cdr< 12-08-2012 12:59 AM

it seems odd that $startdate is a string containing what looks like code

$startdate = 'DATE_SUB(now(), INTERVAL 7 DAY)';


All times are GMT +1. The time now is 06:22 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.