加入两个功能PHP

时间:2011-11-16 19:22:22

标签: php

通过某些功能,我将返回两个功能的值... LIke

<? if(check_status_ticket($result["ticket_id"])) echo 'style="font-weight:bold;"'; ?>

第二个条件是

 <? if($result["priority"]=='Emergency' && $result["status"]=='Open')  echo 'style="color:red;"';?>

我想使用函数组合这两个条件。如果第一个条件为真,则仅返回粗体。如果第二个条件也为真,则它给出红色和粗体但如果两者都为假则返回默认值

function check_status_ticket( $ticket_id ){
      $query = mysql_query( "SELECT ticket_id FROM tkt_newticket WHERE ticket_id='".$ticket_id."' AND response='No' AND status='Open'" ) or die( mysql_error() );
      if(mysql_num_rows($query)=='0'){
          return FALSE;
          }
     else{
      return TRUE; }
}

3 个答案:

答案 0 :(得分:1)

此解决方案可能会帮助您

function check_status_ticket( $ticket_id ){
  $query = mysql_query( "SELECT ticket_id, priority, status FROM tkt_newticket WHERE ticket_id='".$ticket_id."' AND response='No' AND status='Open'" ) or die( mysql_error() );

  if(mysql_num_rows($query) > 0) {

      $row = mysql_fetch_assoc($query);

      if($row["priority"]=='Emergency' && $row["status"]=='Open') return 'style="font-weight:bold; color:red;"';

      return 'style="color:red;"';
  } else return 'style="font-weight:bold;"';

}

答案 1 :(得分:1)

<?php

// ...

// prepare useful variables to ease HTML template reading
$status_ticket = check_status_ticket($result["ticket_id"]);
$open_emergency = ($result["priority"]=='Emergency' && $result["status"]=='Open');

// ...

?>

<html>
...
<?php
  // little computing for style (easy to maintain, but it may be
  // even easier by using CSS classes)

  $style = '';

  if ($status_ticket)
    $style .= 'font-weight:bold;';

  if ($open_emergency)
    $style .= 'color:red;';
?>
<!--
  display step.
  <div> can be replaced by any tag you dream to apply the $style on
-->
<div style="<?php echo $style ?>"></div> 
...
</html>

答案 2 :(得分:0)

首先评估第二个条件,并设置多个样式?

function check_status_ticket( $ticket_id )
{       
 $query = mysql_query( "SELECT ticket_id FROM tkt_newticket WHERE ticket_id='".$ticket_id."' AND response='No' AND status='Open'" ) or die( mysql_error() );       
 if(mysql_num_rows($query)=='0'){           
  return FALSE;           
 }else{       

  if(check_status_ticket($result["ticket_id"])) 
  {
   return 'style="font-weight:bold;"';
  }

  if($result["priority"]=='Emergency' && $result["status"]=='Open')
  {
   return 'style="color:red; font-weight:bold"';
  }

  return TRUE; 
 } 
} 


echo "<a href='#checkticket' " . check_status_ticket($ticket_id) . " class='ticket_class'>";