donglie1994 2010-10-25 22:52
浏览 25

一个简单的PHP问题

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 } ?>
  • 写回答

2条回答 默认 最新

  • dpi10335 2010-10-25 22:59
    关注

    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). :)

    评论

报告相同问题?

悬赏问题

  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类