tags:

views:

126

answers:

2

I have a Joomla module that basically displays a list of categories. Next to the category name, the number of items in that particular category is displayed using the line below

 <em>(<?php echo $row->counter ;?>) </em>  

The items in the categories are set to either ‘open’, ‘close’ or ‘frozen’ and I am trying to make it so that it only displays the number of ‘open’ items and does not include any close or frozen items.

<?php

// no direct access
defined('_JEXEC') or die('Restricted access'); 

$document =& JFactory::getDocument();
$html = '<link href="'.JURI::base(). 'modules/mod_glance_categories/css/style.css" rel="stylesheet" type="text/css" />';
$document->addCustomTag( $html );

$n = 0;
if(count($rows) > 0){

?>
<table width="100%" cellpadding="0" cellspacing="0">
<?php
foreach ( $rows as $row ) 
{
 $n++;
if($n ==1){?>
<tr>   
<?php 
}
if($n <= $columns){
?>
 <td align="left" valign="top" >
 <?php $link_proj_categ = JRoute::_('index.php?option=com_glance&task=categproj&id='.$row->id);?>
 <a href="<?php echo $link_proj_categ;?>" class="tpf_tcatnode">
 <strong><?php echo $row->categories; ?></strong>
 <em>(<?php echo $row->counter ;?>) </em>
 </a>
  </td>
 <?php 
 }
 if($n == $columns){?>
  </tr> 
  <?php 
 $n =0;
   }  
}
$n++;
if($n <= $columns){
 for($x=$n;$x<=$columns;$x++){?>
  <td>&nbsp;</td>
 <?php
}?> 
 </tr> 
 <?php 
 } ?>

  </table>
  <?php } ?>
A: 

If you want "if the status is open", then your if statement should look like:

if(count($rows) > 0 && ($row->status) == "open"){
      // Do something
}

However, in your code, there is $n, which is unused. $rows and $row were not initialized. $rows and $row are different variables (I hope you understand that part). :)

tanjir
Your parentheses don't line up.
Mark E
By the time I wrote it, the question was wrong. Thanks for catching btw.
tanjir
A: 

Without more detail, I'd say your answer is one of the following: (I assume the 2 variables in the condition should have been the same.)

if(count($rows) > 0 && $rows->status) == "open"){
if(count($rows) > 0 && $rows[0]->status == "open"){
if(count($rows) > 0 && $rows['status'] == "open"){
if(count($rows) > 0 && $rows[0]['status'] == "open"){
Fosco
Thanks for the quick response. I tried all of the above but it keeps returning Parse error: syntax error, unexpected T_BOOLEAN_AND in blah/blah/ I'm obviously missing something?
snails07
Your parentheses don't line up.
Mark E
@snails07 My bad.. updated the answer.
Fosco