I have the following in my view for a client that shows a list of appointments for that client:
<h3>Appointments</h3>
<table>
    <?php foreach ($client['Appointment'] as $appointment): ?>
        <tr>
            <td>
                <?php echo $this->Html->link($appointment['date'],
                array('admin' => true, 'controller' => 'appointment', 'action' => 'view', $appointment['id'])); ?>
            </td>
            <td>
                <?php echo $appointment['type']; ?>
            </td>
        </tr>
    <?php endforeach; ?>
</table>
I want to wrap the table in a if statement that checks if any appointments exist and if not then show the following instead:
<p>Client has no appointments. <?php echo $this->Html->l开发者_Go百科ink('Book Appointment', array(
        'admin' => true,
        'controller' => 'appointments',
        'action' => 'add',
        '?' => array('id' => $client['Client']['id']))
    ); ?></p>
How would I do this please?
Thanks
You can use an if statement and empty to determine whether or not the client has any appointments.
<h3>Appointments</h3>
<?php if ( ! empty($client['Appointment']) ): ?>
<table>
    <?php foreach ($client['Appointment'] as $appointment): ?>
        <tr>
            <td>
                <?php echo $this->Html->link($appointment['date'],
                array('admin' => true, 'controller' => 'appointment', 'action' => 'view', $appointment['id'])); ?>
            </td>
            <td>
                <?php echo $appointment['type']; ?>
            </td>
        </tr>
    <?php endforeach; ?>
</table>
<?php else: ?>
<p>Client has no appointments. <?php echo $this->Html->link('Book Appointment', array(
        'admin' => true,
        'controller' => 'appointments',
        'action' => 'add',
        '?' => array('id' => $client['Client']['id']))
    ); ?></p>
<?php endif; ?>
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论