I have a small search engine for a database of songs. I've divided the search and results codes into seperate pages. For some reason I can't get my results to go past 10 even thought I know that there are more records then 10. Can anyone tell me what I'm doing wrong here?
Search engine code:
<?php
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
echo '<form name="form1" method="get" action="searchtitle.php">';
echo 'Search by Title:';
echo '<input type="text" name="words" value="'.$searchwords.'">';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
?>
<br />
<?php
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
echo '<form name="form2" method="get" action="searchalbum.php">';
echo 'Search by Album:';
echo '<input type="text" name="words" value="'.$searchwords.'">';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
?>
<br />
<?php
$searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
echo '<form name="form3" method="get" action="searchwriter.php">';
echo 'Search by Writer:';
echo '<input type="text" name="words" value="'.$searchwords.'">';
echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
?>
Results page code:
<?php
// Full-Text Search Example
// Connect to the database.
require_once ('./includes/mysql_connect.php'); //connect to database
//Records to display per page.
$display = 10;
//Check if the number of required pages has been determined.
if (isset($_GET['no problem'])) { //Already been determined.
$num_pages = $_GET['no problem'];
} else { //Need to determine.
// Count the number of records
$query = "SELECT COUNT(*) FROM master_list WHERE album='$searchstring' ORDER BY song_id";
//$result = mysql_query($query);
//$num_records = mysql_num_rows($result);
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
$num_records = $row[0];
//calculate number of pages.
if ($num_records > $display) {
$num_pages = ceil($num_records/$display);
} else {
$num_pages = 1;
}
} //end of no problem if.
//where to start returning results.
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$searchstring = mysql_escape_string($_GET['words']);
{
$sql = "SELECT song_id, title, album, writer FROM master_list WHERE album='$searchstring' ORDER BY title LIMIT $start, $display";
//$sql = "SELECT song_id, title, album, writer, MATCH (title, album, writer)
//AGAINST ('$searchstring') FROM master_list
//WHERE MATCH(title, album, writer) AGAINST ('$searchstring') ORDER BY title LIMIT $start, $display";
}
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_object($result, MYSQL_ASSOC)) {
//while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//while($row = mysql_fetch_object($result)){
echo '<font size="-1">Title: '.stripslashes(htmlspecialchars($row->title)).'<br /></font>';
echo '<font size="-1">Album: '.stripslashes(htmlspecialchars($row->album)).'<br /></font>';
echo '<font size="-1">Writer: '.stripslashes(htmlspecialchars($row->writer)).'<br /></font>';
echo '<hr size="-1" />';
}
// Make the links to other pages, if necessary.
if ($num_pages > 1) {
echo '<br /><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="searchalbum.php?s='.($start - $display).'&no problem='.$num_pages.'&words='.$searchwords .'">Previous</a> ';
}
// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="searchalbum.php?s='.(($display * ($i - 1))).'&no problem='.$num_pages.'&words='.$searchwords.'">'.$i.'</a> ';
} else {
echo $i.' ';
}
}
// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="searchalbum.php?s='.($start + $display).'&no problem='.$num_pages.'&words='.$searchwords.'">Next</a> ';
}
echo '</p>';
}
// End of links section.
?>