Hello. I am seeking some help on job board script that I am working on. I am trying to use the below script to update the database if the current job is 30 days past the start date or post date. The code below is not working and if I change some things in the code, it will expire every post. Any help will be greatly appreciated. Thanks.

$resultx = mysql_query("SELECT * FROM jobs WHERE active='yes'")
or die(mysql_error());

while ($datax = mysql_fetch_array($resultx,MYSQL_NUM))
      {
        $id = $datax['id'];
        $job_id = $datax['job_id'];
        $sdate = $datax['sdate'];
        $days = $data['days'];

$exp_date = $sdate + (60*60*24*30*3); //the number of seconds in 3 months
//$todays_date = date('Ymd', mktime (0, 0, 0, date ('m'), date ('d'), date ('Y')));
$now = time();

if($exp_date > $now) {
$update = "UPDATE jobs SET active='no' WHERE job_id = ".$job_id;
$results = mysql_query($update);
}
	}

Recommended Answers

All 7 Replies

change MYSQL_NUM to MYSQL_ASSOC. you are trying to use the names of the fields to get their respective values and its not working because you are getting a numeric array.

in the if statement at the end, change the greater than to less than.

Thanks, but it did not work. It sets all of them to expire even though it is not past 30 days.

echo out sdate. is it in unix time format. are the field names right. check stuff like that.

Thanks but I think there is something wrong with my query. I updated my code to this:

$resultx = mysql_query("SELECT * FROM jobs WHERE active='yes'")
or die(mysql_error()); 
      
while ($datax = mysql_fetch_array($resultx,MYSQL_ASSOC))
      {
        $id = $datax['id'];
        $job_id = $datax['job_id'];
        $sdate = $datax['sdate'];
        $days = $data['days'];

$exp_date = strtotime($sdate + (60*60*24*30*3)); //the number of seconds in 3 months
//$todays_date = date('Ymd', mktime (0, 0, 0, date ('m'), date ('d'), date ('Y')));
$now = time();

if($exp_date > $now) {
$update = "UPDATE jobs SET active='no' WHERE job_id = ".$job_id;
$results = mysql_query($update);
}
	}

I added "strtotime" so that it would be equivalent to "time()". It works but it sets every posting in the database to inactive. So, it is not looking at just the one id of the post that is more than 30 days old. That is why I think there is a problem with my query, but I can't figure out the issue.

dump all of your vars and make sure the info in the database is correct. i will give you an sql query as soon as i have more time.

Thanks, I am going to sleep on it as well, so that I will have a clearer head. Thanks again for your help.

change
$update = "UPDATE jobs SET active='no' WHERE job_id = ".$job_id;
to
$update = "UPDATE jobs SET active='no' WHERE job_id = '$job_id'";

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.