2013-04-09 68 views
1

我正在使用新的門票系統,但出現問題。當用戶沒有打開票時,它應該顯示以下消息:門票系統 - 當用戶沒有任何門票時顯示消息

<?}else{?> 
<tr> 
    <td style="background:#f7f7f7;">There are no tickets submitted yet.</td> 
    </tr> 
<?}?> 

我可能做錯了什麼,我弄不清楚在哪裏。這是我的代碼:

<?php 
if($_GET['a'] == "del" && $_GET['id'] != ""){ 
mysql_query("DELETE FROM message WHERE id='{$_GET['id']}' LIMIT 1;"); 
} 

$msg = mysql_query("SELECT * FROM `message` WHERE `receiver`='{$_SESSION['login']}' ORDER BY date DESC")or die (mysql_error()); 
?> 
<table id="nested" width="97%" cellspacing=0 cellpadding=0 style="border-collapse:collapse;"> 
<tr><th width="50px">ID</th><th width="110px">Date</th><th width="165px">Title</th><th width="90px">Status</th><th align="right" width="60px">Actions</th></tr></div> 
<tbody> 
<?php 
while($mesg = mysql_fetch_array($msg)) { 
?> 
<tr class=""> 
<th><?php echo $mesg['id']; ?> </th> 
<td><?php echo $mesg['date']; ?> </td> 
<td><?php echo $mesg['title']; ?> </td> 

<td><?php 
if($mesg['readed']) { echo "Read"; 
}else{ echo "Unread"; 
} ?> </td> 
<th><ul class="action-buttons"> 


<li><a href="#myTickets?id=<?=$mesg['id']?>" class="action-button" title="Read"><span class="read"></span></a></li> 
       <li><a href="#myTickets?a=del&id=<?=$mesg['id']?>" class="action-button" title="Delete"><span class="delete"></span></a></li> 
       <li><a href="#myTickets?a=close&id=<?=$mesg['id']?>" class="action-button" title="Close"><span class="close"></span></a></li></ul> 

<? } ?> 

</th> 

<?}else{?> 
    <tr> 
     <td style="background:#f7f7f7;">There are no tickets submitted yet.</td> 
     </tr> 
    <?}?> 

</tr> 

</tbody> 
</table> 
</table> 

請如果有人能幫助我,我將非常感謝,謝謝!

回答

0

沒有if聲明匹配else。當有票時,可以添加if,或者只需將else更改爲if,當不是票時,評估值爲true

例如:

<?if (mysql_num_rows($msg) == 0) {?> 
    <tr> 
     <td style="background:#f7f7f7;">There are no tickets submitted yet.</td> 
    </tr> 
<?}?> 
+0

如何修改此代碼,在哪裏添加if語句? – user2263216 2013-04-09 19:27:08

+0

希望這會指出你在正確的方向。但是你需要閱讀'if'語句中的php文檔。 [「if'構造是許多語言中最重要的特性之一,包括PHP。」](http://www.php.net/manual/en/control-structures.if.php) – 2013-04-09 19:34:20

+0

正在工作! !非常感謝你的幫助!! – user2263216 2013-04-09 19:37:12

0

請檢查您的大括號。它不平衡。

<?php 
    if(mysql_num_rows($msg) == 0) { ?> //means the query returns empty set. 
     <tr> 
      <td style="background:#f7f7f7;"> //There are no tickets submitted yet.</td> 
     </tr> 
<?php } else { // you have messages 
    while($mesg = mysql_fetch_array($msg)) { 
     // finish ur while loop 
?> 
+0

對不起,我在PHP新的,我不明白你的意思有什麼用?你可以做如在哪裏兌換? – user2263216 2013-04-09 19:29:50