簡體   English   中英

一個簡單的PHP問題

[英]A simple PHP question

我有一個Joomla模塊,該模塊基本上顯示類別列表。 在類別名稱旁邊,使用以下行顯示該特定類別中的項目數

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

類別中的項目設置為“打開”,“關閉”或“凍結”,而我正在嘗試使其僅顯示“打開”項目的數量,而不包括任何關閉或凍結的項目。

<?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 } ?>

如果要“狀態為打開”,則if語句應類似於:

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

但是,在您的代碼中,有$ n未被使用。 $ rows和$ row未初始化。 $ rows和$ row是不同的變量(希望您理解這一部分)。 :)

如果沒有更多的細節,我會說您的答案是以下之一:(我假設條件中的2個變量應該相同。)

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"){

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM