1

我最近在我的搜索脚本(使用下拉菜单)中添加了分页,每页只显示 10 个项目。第一页显示正确,但是当我单击下一步按钮时,我从下拉列表中选择时出现错误...最初我将搜索引擎设置为这样,以防用户不指定他们想要搜索的内容。我不知道如何或如何做才能使整个寻呼工作正常工作,这是编程新手。帮助

这是我的脚本

索引页

<html> 
<head> 
<title>SLAM</title>
<basefont face="Arial"> 
</head> 
<body>
<form action='search.php' method='GET'>
<center>
<h1>ONLINE ACCESS CATALOG</h1>
<select size="1" name="dropdown"> 
<option value="" selected>Search By...</option> 
<option value="main_title">Title</option> 
<option value="author1">Author</option> 
<option value="subj1">Subject</option>
</select> 
<input type="text" size='90' name="search"><br><br>
<input type="Submit" value="Submit" name="Submit">
</center>
</form>
</body> 
</html>    

搜索页面

?php
    //Server Variables 
    $host = "localhost"; 
    $user = "root"; 
    $pass = "erhun"; 
    $db = "books";


    $search = empty($_GET['search'])? die ("<font size='5'font color='#FF0E0E'>ERROR: Enter Search Criteria</font>") : mysql_real_escape_string($_GET['search']); 
    $dropdown = empty($_GET['dropdown'])? die ("<font size='5'font color='#FF0E0E'>ERROR: Select from Dropdown</font>") : mysql_real_escape_string($_GET['dropdown']);


//Open Connection
$connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");

//Select Database
mysql_select_db($db) or die ("Unable to connect to database");

// set $page to number 1 for the first page
if(@$page == ""){

    $page = "1";

}else{

    // getting page
    $page = $_GET['page'];

}


@$sql = "SELECT book_id,call_no,main_title,author1,itm_type,publdate,image,subj1 FROM records WHERE $dropdown LIKE '%$search%'";
$query = mysql_query($sql);


@$num = mysql_num_rows($query);


$per_page = "10";


$last_page = ceil($num/$per_page);


$first_page = "1";


echo "<a href='?page=".$first_page."'>First page</a> ";


if($page == $first_page){

    echo "Previous ";

}else{

    if(!isset($page)){

        echo "Previous ";

    }else{


        $previous = $page-1;
        echo "<a href='?page=".$previous."'>Previous</a> ";

    }

}

// If the page is last page.. lets remove "Next" link
if($page == $last_page){

    echo "Next ";   

}else{


    if(!isset($page)){

        $next = $first_page+1;
        echo "<a href='?page=".$next."'>Next</a> ";

    }else{

        $next = $page+1;
        echo "<a href='?page=".$next."'>Next</a> ";

    }

}

// And now lets add the "Last page" link
echo "<a href='?page=".$last_page."'>Last page</a>";


$start = ($page-1)*$per_page;


$limit = "LIMIT $start, $per_page";


$sql = "SELECT book_id,call_no,main_title,author1,itm_type,publdate,image,subj1 FROM records WHERE $dropdown LIKE '%$search%' $limit";
$query = mysql_query($sql);

echo "<br /><br />";

$i=0; 
echo "<table id='query'>";
// And lets display our messages
while($row = mysql_fetch_array($query) or die(mysql_error())){

$book_id=mysql_result($query,$i,"book_id");
$image=mysql_result($query,$i,"image"); 
$main_title=mysql_result($query,$i,"main_title"); 
$call_no=mysql_result($query,$i,"call_no"); 
$publdate=mysql_result($query,$i,"publdate"); 
$author1=mysql_result($query,$i,"author1"); 
$itm_type=mysql_result($query,$i,"itm_type"); 
$subj1=mysql_result($query,$i,"subj1"); 

echo "
<tr><td><img src='image1/$image' alt='Image not found' onError=this.onerror=null;this.src='image1/default.jpg' height='110px' width='90px'></td><td valign='top'><b><a href=details.php?id=$book_id>
<b>$main_title</b></a></b><br>
<b>By:</b> $author1<br>
<b>Call no:</b> $call_no<br>
<b>Type:</b> $itm_type<br>
<b>Year:</b> $publdate</tr><p>
<hr color='#7dd5f5' size='1'></br>
";

$i++;
echo "<table>";
}
?>
4

0 回答 0