Help with an if statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    Help with an if statement

    [PHP]$query = "select * from jobs where user_id = '".$_SESSION['user_id']."'";
    $result = @mysql_query ($query);
    $num = mysql_num_rows( $result);
    if ($num >0)
    {
    echo "<tr><th colspan='2' width='100%' align='left'>Jo b Position</th></tr>";

    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
    {
    $job_position = stripslashes($r ow['job_position']);
    $id = $row['id'];
    $submitted = $row['submitted'];

    echo "
    <tr>
    <td width='50%'><fo nt face=arial size=2><!--$id-->$job_positio n</a></font></td>
    <td width='50%'><fo nt face=arial size=2>Current Status:
    ";
    if ($submitted > SUBDATE(NOW(), INTERVAL 30 DAY))
    {
    echo "Expired";
    }
    else
    {
    echo "Active";
    }

    echo "
    </td>
    </tr>";[/PHP]

    I'm getting an error message "unexpected T_LNUMBER " with this if statement. $submitted is the date the ad was created, ads created within 30 days is considered active and ads over 30 days are expired.

    I've read that you cannot start a variable with a number, so how can I do this?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Which if statement?

    Also, subtime() isnt a php function.

    Regards.

    Comment

    • DavidPr
      New Member
      • Mar 2007
      • 155

      #3
      Sorry, this one:
      [PHP]if ($submitted > SUBDATE(NOW(), INTERVAL 30 DAY))
      {
      echo "Expired";
      }
      else
      {
      echo "Active";
      }

      echo "
      </td>
      </tr>";[/PHP]
      $submitted is a date and you can't have a variable that starts with a number in an if statement, so it seems. I'm wondering if there may be a work around this that would still allow me to decide which to use (Expired or Active) based on the date the ad was submitted .vs current date.

      Thanks

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        What's SUBDATE(NOW(), INTERVAL 30 DAY)?

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by hsriat
          What's SUBDATE(NOW(), INTERVAL 30 DAY)?
          That's a mysql clause...

          If it's mysql, it isn't a php function, if it isnt a php function, then i'm at a loss.

          :|

          You'll need to explain to us what the aforementioned does, and we'll see if we can rememdy it with some good ol' phpery!

          Regards.

          Comment

          • DavidPr
            New Member
            • Mar 2007
            • 155

            #6
            I use it in a mysql query on the public side of my website to display current job ads:

            [PHP]$query = "SELECT * FROM jobs WHERE submitted > SUBDATE(NOW(), INTERVAL 30 DAY)";[/PHP]

            It will only display jobs that has been submitted within the past 30 days. What I'm trying to do is allow an employer to see the status of all the job ads s/he has posted - Active or Expired. Job ads that are over 30 days old are no longer displayed to the public, so they will have the option of either renewing the ad for another 30 days or deleting it.

            I was trying to come it with an if statement that would check the date ($submitted) when the job ad was submitted or renewed and would set the Status (Active or Expired) based on whether the $submitted date was within the past 30 days (Active) or over 30 days (Expired).

            Comment

            Working...