2011-11-16 100 views
-5

通過某些種類的功能,我回到2個functins值...像連接兩個函數Php

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

回答

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;"'; 

}

+0

使用 「幻數」 不會使這個非常可讀... – RoToRa

+0

退房現在的樣子,你說得對,現在看起來更可讀......;) – norman784

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'>"; 
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>