SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: PHP search help

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

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

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    Try inserting these lines at the bottom of your script:

    PHP Code:

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

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    John_Betong,

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

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    @storm925

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •