0

Hi Guys,
I'm a bit of a newbie, but I like to think I learn quick :)

I have a piece of code that's working well to show that a job listing has expired. Can anyone tell me if there is a simple way of telling it not to show at all. Ideally if a job entry has expired it doesn't want to be seen in the front end.

I've done a lot of searching, copying, pasting and tweaking, but can't find anything that can do the job.

the code is...

<td>
<a href="<?php echo $link_detail; ?>"><?php echo $row->job_title; ?></a><?php $now = date('Y-m-d H:i:s', time() + ( $mainframe->getCfg('offset') * 60 * 60 ) );

if($row->expire_date != "0000-00-00 00:00:00" && $row->expire_date < $now)
{
echo '(expired)';
}
?>					
</td>

Any pointers would be really greatly appreciated.

Thanks in advance

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tsp003
0

The simplest way would be to change your SQL Select statement's Where clause to exclude any records that are marked as expired. If you still want to see those records for another reason then you can do it in the code:

if($row->expire_date != ...    ) {
   echo "<a href=...
}

Some people seem to prefer embedding little bits of PHP in html code but I find that it makes it difficult to read. My preference is to embed the html within PHP. I find it cleaner to write:

if($row->expire_date != "0000-00-00 00:00:00" && $row->expire_date < $now) {
 echo "
  <td>
  <a href=$link_detail.$row->job_title...
  </td>
 "
endif

If there is a performance impact, it is trivial. I think that the amount of time spent debugging is a lot more important. When you do it this way you may have to escape any embedded quotes (e.g. \") but that's a small price to pay.

Edited by chrishea: n/a

0

Thanks for the reply.

Must be me (im almost sure it is :icon_cheesygrin:)but i've tried changing the SQL statement as suggested, to a "WHERE expire_date >= CURDATE()" but this resulted in no records displaying for that category.

As i've inherited this site/code, i'm having a little trouble getting my head around whats going on here. All i can say is that i've changed it to 'mark' the record expired when as i said before it should be hidden.

On further inspection I see that we have a two files and it looks to me like the searchbyspec function is being duplicated in each file rather than being stored in one place (but im a newbie, i'm probably wrong there too)

If anyone could help me understand it or give any further advice i'd be grateful

The file with the SQL looks like this....

//searchBySpec
function searchBySpec($option){
	global $mainframe;
	$user	=& JFactory::getUser();
	$id 	= (int)JRequest::getVar('id', 0, 'get', 'string');
	if(empty($id))
	{
		$return = JRoute::_('index.php?option=com_tpjobs');
		$mainframe->redirect($return);
		return;
	}
	// Initialize variables
	$db 	= & JFactory::getDBO();		
	
	//for header title
	$query = "select a.id,specialization,category ".
		 		" from #__tpjobs_job_spec a ".
				" left join #__tpjobs_job_categ b".
				" ON a.id_category = b.id".
				" where a.id = ".$db->quote( $id );
				
	$db->setQuery($query);	
	$categ = $db->loadObjectList();
	$spec = (!empty($categ[0])) ? $categ[0] : null;

	$keyword="";
	$where ="where a.job_title like '%".$keyword."%'";
	$where .=" and id_job_spec =".$db->quote( $id )." ";
	$now = date('d-m-Y H:i:s', time() + ( $mainframe->getCfg('offset') * 60 * 60 ) );
	$where .= "and a.is_active='y' and expire_date > '".$now."' and expire_date <> '0000-00-00 00:00:00'";

	$limit		= $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');

	$limitstart			= JRequest::getVar('limitstart',0,'','int');
	
	
	$query = "SELECT COUNT(*)".	          
			 " from #__tpjobs_job a".
	      	 " left join #__tpjobs_country b".
			 " ON a.id_country = b.country".
		 	 " left join #__tpjobs_employer c".
			 " ON a.employer_id = c.user_id".
			 " left join #__tpjobs_comp_type d".
			 " ON c.id_comp_type = d.id ".$where.
			 " ORDER BY a.publish_date DESC";
			 	
	
	$db->setQuery( $query );
	$total = $db->loadResult();
	
	jimport('joomla.html.pagination');
	$pageNav = new JPagination( $total, $limitstart, $limit );


	$query ="select a.*,country,comp_name,comp_type,expire_date".
			 " from #__tpjobs_job a".
	      	 " left join #__tpjobs_country b".
			 " ON a.id_country = b.id".
		 	 " left join #__tpjobs_employer c".
			 " ON a.employer_id = c.user_id".
			 " left join #__tpjobs_comp_type d".
			 " ON c.id_comp_type = d.id ".$where.
			 " ORDER BY a.publish_date DESC";
	
	
	$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
	
	$rows = $db->loadObjectList();	
	
	HTML_front_tpjobs::searchBySpec($rows,$spec,$pageNav,$option);
}

and the other one's code looks like this

//searchByCateg
function searchBySpec(&$rows,$spec,&$pageNav,$option)
{	
		$user = & JFactory::getUser();	
		$id   = (int)JRequest::getVar('id', 0, 'get', 'string');	
		$post   = JRequest::get('post');
		if($id==0){
			$id= (!empty($post['id'])) ? $post['id'] : null;
		}
		$action	= JRoute::_('index.php?option=com_tpjobs&task=searchbycateg&id='.$id);
		$is_employer  = isEmployer($user->id);
		$is_jobseeker = isJobSeeker($user->id);
		global $mainframe;
	$config = & JComponentHelper::getParams( 'com_tpjobs' );
	$now = date('Y-m-d H:i:s', time() + ( $mainframe->getCfg('offset') * 60 * 60 ) );
	$where = "b.is_active='y' and b.expire_date > '".$now."' and b.expire_date <> '0000-00-00 00:00:00'";
		
		?>
	
		<h3 class="tpj_h3title"><b><?php echo JText::_('LIST OF JOB'); ?></b></h3>
		
		
		<h3><strong><?php echo JText::_('CATEGORY'); ?> </strong> :
<?php echo $spec->category; ?> - 
	<strong><?php echo JText::_('SPECIALIZATION'); ?> </strong> :
<?php echo $spec->specialization; ?></h3>

		
		<form action="<?php echo $action; ?>" method="post" name="userFormJob" enctype="multipart/form-data">	
			<table width="100%" cellpadding="0" cellspacing="0">
			<thead>
				<tr class="tpj_rowhead">
					<th width="10">
						<?php echo JText::_('NO'); ?>
					</th>
					
					<th width="10%" align="left">
						<?php echo JText::_('DATE'); ?>
					</th>
					
					<th width="30%" align="left">
						<?php echo JText::_('JOB TITLE'); ?>
					</th>
					
					<th width="20%" align="left">
						<?php echo JText::_('LOCATION'); ?>
					</th>
					
					<th  align="left">
						<?php echo JText::_('COMPANY'); ?>
					</th>
					
									
					
				</tr>
			</thead>
			<tfoot>
				<tr>
					<td colspan="6" class="tpj_row3">
						<?php echo $pageNav->getListFooter(); ?>
					</td>
				</tr>
				<tr>
					<td colspan="6" class="tpj_row3">
						<a href="<?php echo JRoute::_('index.php?option=com_tpjobs&task=rss&type=specialization&id='.$id); ?>"><img src="<?php echo JURI::root(); ?>components/com_tpjobs/images/rss.png" alt="RSS"></a>
					</td>
				</tr>
			</tfoot>
			<tbody>
			<?php
			$k = 0;
			for ($i=0, $n=count($rows); $i < $n; $i++) {
				$row = $rows[$i];

				
				$link_detail	= JRoute::_('index.php?option=com_tpjobs&task=detailjob&id='. $row->id );
				$link_publish	= JRoute::_('index.php?option=com_tpjobs&task=publishjob&id='. $row->id );
				?>
				<tr class="tpj_<?php echo "row$k"; ?>">
					<td>
						<?php echo $pageNav->getRowOffset( $i ); ?>
					</td>
					<td>
					<?php echo JHTML::_('date', $row->publish_date, '%d-%m-%Y'); ?>
					</td>
					
					<td>
					<a href="<?php echo $link_detail; ?>"><?php echo $row->job_title; ?></a><?php
						$now = date('Y-m-d H:i:s', time() + ( $mainframe->getCfg('offset') * 60 * 60 ) );
						if($row->expire_date != "0000-00-00 00:00:00" && $row->expire_date < $now)
						{
							echo '(expired)';
						}
					?>	
                                        				
					</td>
					<td>
					<?php echo $row->state; ?>, <?php echo $row->country; ?>
					</td>
					<td>
					<?php echo $row->comp_name; ?>
					</td>				
				</tr>
				<?php
				$k = 1 - $k;
			}
			?>
			</tbody>
			</table>

		
		</form>
<? 		
	}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.