Domanda

I am working on a new ticket system, but something went wrong. When a user does not have an open ticket, it should show this message:

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

I probably did something wrong and I cannot figure out where. This is the code that I have:

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

Please if anyone can help me, I would appreciate it very much, thank you!

È stato utile?

Soluzione

There is no if statement to match the else. Either add an if for when there are tickets, or just change the else into an if that evaluates to true when there aren't tickets.

For example:

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

Altri suggerimenti

Please check your braces. Its not balanced.

<?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
 ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top