f
Hi there,
i have a search page that is supposedly going to display results by batches of 30.
Now, it does display the first 30 results fine but when i click on next, it loads-up the
page but it doesnt display the next batch of results. its driving me crazy!
i think what im doing is called pageination or something like that. It automaticaly determines
how many resuts have been found, automatucally creates links for the pages that will display the next set
of results, and should display the results by batches accordingly.
The page can be found at http://www.rxpinoy.com/search_doctors.php
Below is the code im using. Hope anybody can help me. TNx!
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<p><legend><b><font color="#006699" size="4" face="Arial, Helvetica, sans-serif">Doctors Search:</font></b></legend><br />
<small><font size="2" face="Arial, Helvetica, sans-serif">Type the First Name or Last
Name in the box below then Click on the Search Button.</font></small><br />
<input type="text" name="ejohn" size="55" maxlength="20" />
<input type="submit" name="submit" value="Search" />
</p>
</fieldset>
<p> </p>
</form>
<!-- End of Form -->
// Handle the form
if (isset($_POST['submit'])) {
require_once ('../mysqlconnect_search.php'); // Connect to the database.
// Check for Data Sent through the Form Below
if (eregi ("^[[:alpha:].' -]{2,15}$", stripslashes(trim($_POST['ejohn'])))) {
$ej = escape_data($_POST['ejohn']);
} else {
$ej = FALSE;
echo '<p><font color="red" size="+1">Please type a Name or Specialty on the search box.</font></p>';
}
if ($ej) { // If everything's OK. ----CLOSE THIS
// Number of records to show per page:
$display = 40;
echo '<p>Click on <b>Ask-a-Doc</b> to ask a question or Click <b>Webprofile</b> to see the Doctor\'s Profile Information</p>';
// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.
$num_pages = $_GET['np'];
} else { // Need to determine.
$query = "SELECT docid, firstname, middlename, LOWER(lastname), title, fieldid FROM TDOCTORS WHERE lastname='$ej' OR firstname='$ej' OR FIELDID='$ej' ORDER BY lastname ASC"; // Standard query.
$query_result = mysql_query ($query);
$num_records = @mysql_num_rows ($query_result);
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}
}
// Determine where in the database to start returning results.
if (isset($_GET['s'])) { // Already been determined.
$start = $_GET['s'];
} else {
$start = 0;
}
// Make the query.
$query = "SELECT docid, firstname, middlename, LOWER(lastname), title, fieldid FROM TDOCTORS WHERE lastname='$ej' OR firstname='$ej' OR fieldid='$ej' ORDER BY lastname ASC LIMIT $start, $display";
$result = @mysql_query ($query); // Run the query.
$num = mysql_num_rows ($result); // How many doctors are there?
if ($num > 0) { // If it ran OK, display the records.
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo '<p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;
// If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="search_doctors.php?s=' . ($start - $display) . '&np=' . $num_pages . '"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">Previous</font></a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="search_doctors.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">' . $i . '</font></a> ';
} else {
echo $i . ' ';
}
}
// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="search_doctors.php?s=' . ($start + $display) . '&np=' . $num_pages . '"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">Next</font></a>';
echo "<br /><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">Displaying 30 at a time. Click on a name to view his or her profile</font>";
}
echo '</p><br /><br />';
} // End of links section.
// Table header.
echo '<table align="left" cellspacing="2" cellpadding="2">
<tr><td align="left"><b>First Name </b></td><td align="left"><b>Middle Name </b></td><td align="left"><b> Last Name </b></td><td align="left"><b> </b></td><td align="left"><b>Specialty</b></td><td align="left"><b> </b></td><td align="left"><b> </b></td></tr>';
// Fetch and print all the records.
$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$bg = ($bg=='#f5faff' ? '#ffffff' : '#f5faff'); // Switch the background color.
//make values into constants
$result_docid = "{$row['0']}";
$result_firstname = "{$row['1']}";
$result_middlename = "{$row['2']}";
$result_lastname = "{$row['3']}";
$result_title = "{$row['4']}";
$result_field = "{$row['5']}";
if ($result_field=='ACP') {
$result_specialty = "Pathology, Anat. & Clin";
} elseif ($result_field=='ADO') {
$result_specialty = "Adolescent Medicine";
} elseif ($result_field=='ALM') {
$result_specialty = "Allergy & Immunology";
} else {
$result_specialty = "General Practice";
}
echo '<tr bgcolor="', $bg, '"><td align="left">' . $result_firstname . ' </td><td align="left">' . $result_middlename . ' </td><td align="left">' . $result_lastname . ' </td><td align="left">' . $result_title . ' </td><td align="left">' . $result_specialty . '</td><a href=http://www.rxpinoy.com/askadoc/' . $result_lastname . ' alt="Click here to ask a question"><td align="left"><img src="index/index_misc/searchresults_askadoc.jpg" width="77" height="16" /></td></a><a href=http://www.rxpinoy.com/members/' . $result_docid . ' alt="Click here to see web profile"><td align="left"><img src="index/index_misc/searchresults_webprofile.jpg" width="77" height="16" /></td></a></tr>';
} // End of while loop 1.
echo '</table><br />'; // Close the table.
mysql_free_result ($result); // Free up the resources.
} else { // If there are no registered users.
echo '<h3>No Matches Found. Please Try Again.</h3>';
}
mysql_close(); // Close the database connection.
}
}