0; $total_pages--) { if ($page != $current_page_number) echo ""; echo "$page "; if ($page != $current_page_number) echo ""; $page++; } } echo "

Search Members

ID:

Username:

Email:

"; /** * Display Search Results Below Here **/ //load the current paginated page number $page = ($_GET['page']) ? $_GET['page'] : 1; $start = ($page-1) * NUMBER_PER_PAGE; /** * if we used the search form use those variables, otherwise look for * variables passed in the URL because someone clicked on a page number **/ $id = ($_POST['id']) ? $_POST['id'] : $_GET['id']; $username = ($_POST['username']) ? $_POST['username'] : $_GET['username']; $email = ($_POST['email']) ? $_POST['email'] : $_GET['email']; $sql = "SELECT * FROM members WHERE 1=1"; if ($id) $sql .= " AND id='" . mysql_real_escape_string($id) . "'"; if ($username) $sql .= " AND username='" . mysql_real_escape_string($username) . "'"; if ($email) $sql .= " AND email='" . mysql_real_escape_string($email) . "'"; //this return the total number of records returned by our query $total_records = mysql_num_rows(mysql_query($sql)); //now we limit our query to the number of results we want per page $sql .= " LIMIT $start, " . NUMBER_PER_PAGE; /** * Next we display our pagination at the top of our search results * and we include the search words filled into our form so we can pass * this information to the page numbers. That way as they click from page * to page the query will pull up the correct results **/ pagination($page, $total_records, "id=$id&username=$username&email=$email"); $loop = mysql_query($sql) or die ('cannot run the query because: ' . mysql_error()); while ($record = mysql_fetch_assoc($loop)) echo "
{$record['id']}) " . stripslashes($record['username']) . " - {$record['email']}"; echo "
" . number_format($total_records) . " search results found
"; pagination($page, $total_records, "id=$id&username=$username&email=$email"); ?>