SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: count

  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    count

    I want to add fuctionality to a search result page that:
    a) displays "no results found" if there are none,
    b) divides the results into 10 listings per page,
    c) displays how many results found if there are some,
    (i.e. 330 teachers found. Displaying 11 to 20.)
    d) provides "Next 10" and "Previous 10" links.

    Can anyone point me to resources?

    Here is my code:

    PHP Code:
    <?php
    $teachers 
    mysql_query($select $from $where $order);
    if (!
    $teachers) {
     echo(
    "<p>Error retrieving articles from database!<br />".
      
    "Error: " mysql_error() . "</p>");
     exit();
    }
    while (
    $teacher mysql_fetch_array($teachers)) {
     
    $teacher_id $teacher["teacher_id"];
     
    $firstname $teacher["firstname"];
     
    $lastname $teacher["lastname"];
     
    $preferred_name $teacher["preferred_name"];
     
    $city $teacher["city"];
     
    $state $teacher["state"];
     
    $zip $teacher["zip"];
     
    $country $teacher["country"];
     
    $workphone $teacher["workphone"];
     
      echo(
    "<p>$firstname $lastname ($preferred_name)<br />$city$state$zip$country<br />
    Email: 
    $internet  Phone: $workphone<br /></p>\n");
    }
    ?>
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SitePoint Addict RapidGaming's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the "No results" try the following:

    PHP Code:
    <?php
    if(mysql_num_rows($teachers) == '0') DIE ("No results matched your query.");
    ?>

  3. #3
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's my class for iterating over pages: http://chrisken.utacm.org/source.pht...geIterator.php

    You could potentially use it if you also used the database class or changed the relevant lines to use the standard mysql functions.
    ck :: bringing chris to the masses.

  4. #4
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks RapidGaming, your code worked fine.
    Thanks Anarchos, I'm studying your code.
    Paul C.
    ClickBasics
    http://www.clickbasics.com


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
  •