PHP search help

Hello Forum,

I have been going through the sitepoint book “Build Your Own Database Driven Web Site Using PHP & MYSQL” (4th edition) and was hoping to get some help with a question. On page 225, the book states… “If you’re up for the challenge, try adding a little code to this template to handle gracefully the case where no jokes satisfy the criteria specified in the search form.” Below is the code from the book referenced in the challenge. I have not been able to get the output to deliver a “no jokes satisfy the criteria specified” and I am now looking for some help here. Thank you for reading my post and any suggestions would be greatly appreciated. --Ben

<h1>Search Results</h1>
<?php if (isset($jokes)): ?>
    <tr><th>Joke Text</th><th>Options</th></tr>
    <?php foreach ($jokes as $joke): ?>
    <tr valign="top">
      <td><?php htmlout($joke['text']); ?></td>
        <form action="?" method="post">
            <input type="hidden" name="id" value="<?php htmlout($joke['id']); ?>"/>
            <input type="submit" name="action" value="Edit"/>
            <input type="submit" name="action" value="Delete"/>
    <?php endforeach; ?>
<?php endif; ?>

Try inserting these lines at the bottom of your script:

<?php else: /* INSERT THIS AND THE NEXT LINE */ ?>
  <h4> no jokes satisfy the criteria specified </h4>
<?php endif; ?>


Thank you for the reply, that worked perfectly! I guess I was making it more complex than it needed to be. --Ben


'glad I was able to help - when you cannot see the problem it is no joke :slight_smile: