Page 1 of 1
Help undersdtanding the IF statement
Posted: Wed Apr 27, 2011 7:12 am
by tsp003
I'm learning, so please be nice if this is a stupidly ridiculous question
i've been having some troubles getting values displayed on my site, which you lovely people have helped me fix.
The latest is as follows
Code: Select all
<td>
<span class="tpj_location"><?php if($row->city !="") { echo $row->city.","; }?>
<?php if($row->state !="") { echo $row->state."<br/>"; }?></span>
<em><?php if($row->country !="") { echo $row->country; }?></em>
</td>
My actual problem is that when this code is output it is displaying the country value, but not the state and city (im getting the record numbers for them instead). I've had similar problems in the back end of my site (joomla) which i've resolved, but the code there was very different and being a noob i've not come yet across IF statements.
So I'm not fully understanding this code. I know that the IF statement is used to get something to to happen IF a certain criteria is met, but i don't know what's actually being required from this code, or how the country field is pulling the text value and ignoring the record number/id.
so can someone tell me:-
1. what
!="" does in above code
2. some reasons why the country field would be displayed and the other two fields are only displaying record numbers.
Thanks
Re: Help undersdtanding the IF statement
Posted: Wed Apr 27, 2011 7:24 am
by JustPlainJef
tsp003 wrote:I'm learning, so please be nice if this is a stupidly ridiculous question
i've been having some troubles getting values displayed on my site, which you lovely people have helped me fix.
My actual problem is that when this code is output it is displaying the country value, but not the state and city (im getting the record numbers for them instead). I've had similar problems in the back end of my site (joomla) which i've resolved, but the code there was very different and being a noob i've not come yet across IF statements.
So I'm not fully understanding this code. I know that the IF statement is used to get something to to happen IF a certain criteria is met, but i don't know what's actually being required from this code, or how the country field is pulling the text value and ignoring the record number/id.
so can someone tell me:-
1. what
!="" does in above code
2. some reasons why the country field would be displayed and the other two fields are only displaying record numbers.
Thanks
I don't have all the answer, but != means Not equal. So
if($row->city !="") { echo $row->city.","; } means If the city in the row is not blank, echo the city, followed by ", " So for London, you would see "London, ". If the city is blank, it doesn't echo anything.
As for why the Country field would come up but not the other two, I think we need more info.
Re: Help undersdtanding the IF statement
Posted: Wed Apr 27, 2011 8:00 am
by tsp003
Thanks for replying, im understanding the code better now.
There are three files at work here
mod_tpjobslatest.php:
Code: Select all
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( dirname(__FILE__).DS.'helper.php' );
$total_row = intval( $params->get( 'total_row',5) );
$rows = modTPJobsLatestHelper::getLatestJobs($total_row);
require( JModuleHelper::getLayoutPath('mod_tpjobslatest') );
?>
deafult.php
Code: Select all
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
if (!function_exists('call_css_mod_tpjobslatest')) {
function call_css_mod_tpjobslatest() {
$document = & JFactory::getDocument();
$document->addCustomTag( '<link rel="stylesheet" type="text/css" href="'. JURI::base() . 'modules/mod_tpjobslatest/css/style.css"/>' );
}
call_css_mod_tpjobslatest();
}
?>
<?php
$link_simple_search = JRoute::_('index.php?option=com_tpjobs&task=detailjob');
?>
<table width="100%" cellpadding="0" cellspacing="0" class="tpj_tbl">
<tr class="sectiontableheader">
<td width="10%" align="left">
<?php echo JText::_( 'Posted' ); ?>
</td>
<td width="40%" align="left">
<?php echo JText::_( 'Description' ); ?>
</td>
<td width="30%" align="left">
<?php echo JText::_( 'Location' ); ?>
</td>
<td width="20%" align="left">
<?php echo JText::_( 'Company' ); ?>
</td>
</tr>
<?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 );
?>
<tr class="tpj_<?php echo "row$k"; ?>">
<td>
<span class="tpj_date"><?php echo JHTML::_('date', $row->publish_date, '%d') ;?></span><br />
<span class="tpj_month"><?php echo JHTML::_('date', $row->publish_date, '%b') ;?></span>
</td>
<td>
<a href="<?php echo $link_detail;?>" class="tpj_title"><?php echo $row->job_title; ?></a>
</td>
<td>
<span class="tpj_location"><?php if($row->city !="") { echo $row->city.","; }?>
<?php if($row->state !="") { echo $row->state."<br/>"; }?></span>
<em><?php if($row->country !="") { echo $row->country; }?></em>
</td>
<td>
<?php
$img = JPATH_SITE.DS.'images'.DS.'tpjobs'.DS.$row->employer_id.'.jpg';
if(file_exists($img)) {
$img = JURI::base().'images/tpjobs/'.$row->employer_id.'.jpg';
echo '<img class="tpj_imglatest" src="'.$img.'" width="50" height="50" style="margin-right:10px;" alt="img"/>';
}
else if($row->id)
{
$img = JURI::base().'components/com_tpjobs/images/nophoto.gif';
echo '<img class="tpj_imglatest" src="'.$img.'" width="50" height="50" style="margin-right:10px;" alt="img"/>';
}
?><br />
<div class="tpj_compname"><?php echo $row->comp_name; ?></div>
</td>
</tr>
<?php
$k = 1 - $k;
}
?>
</table>
and helper.php
Code: Select all
?php
/**
* helper.php
*Module : mod_tpjobslatest
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
global $mm_action_url,$sess;
class modTPJobsLatestHelper{
function getLatestJobs($total_row)
{
global $mainframe;
$db = & JFactory::getDBO();
$now = date( 'Y-m-d H:i:s', time() + ( $mainframe->getCfg('offset') * 60 * 60 ) );
$where = " WHERE a.is_active='y' and a.publish_date<>'0000-00-00 00:00:00' and a.expire_date > '".$now."' and a.expire_date <> '0000-00-00 00:00:00' ";
//make selection country
$query = "SELECT a.* ,b.comp_name,c.country ".
" FROM #__tpjobs_job a ".
" LEFT JOIN #__tpjobs_employer b".
" ON a.employer_id = b.user_id ".
" LEFT JOIN #__tpjobs_country c".
" ON a.id_country =c.id". $where.
" order by publish_date desc".
" LIMIT 0,". $total_row ;
$db->setQuery( $query );
$rows = $db->loadObjectList();
return $rows;
}//end function
}//end of class
?>
deafult.php is the one containing the original code i posted. i'm suspecting its the helper file as its obvioulsy doing something with the country and not making any reference to city or state, but i'm not sure if that is the case, or how to amend it.