Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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++;
    }
     
    ?> 
    Last edited by Inigoesdr; 12-08-2012 at 04:22 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    May 2007
    Posts
    108
    Thanks
    19
    Thanked 13 Times in 13 Posts
    it seems odd that $startdate is a string containing what looks like code

    $startdate = 'DATE_SUB(now(), INTERVAL 7 DAY)';
    The CodingForums Funny Images thread ** Now with 20+ pages!! ** - http://www.codingforums.com/showthread.php?t=245405


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •