我对Get & Post进行了更改,但它没有提供任何内容,我认为它的形式使得这个问题变得困难,这个部分下面的表单在这里,我做错了什么?我不知道,但知道一件事,当我使用'名称',而不是'提交'&'去'GET & POST我得到错误说undefined索引:'名称',怎么了,我做了你所说的,但没有什么!我如何获取数据以显示在其他页面上?
/////////////表单/////////////////////
<form method="post" action="search_govern.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Yell">
</form>
/表/////////////////////
<?php
//if(isset($_POST['submit'])){
//if(isset($_GET['go'])){
//if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
//$name=$_POST['name'];
////////////////////////////////////////
的//////////最后,我认为这个问题是在这里,但我不确定我做错了什么,请你指出我的错误或给我看一个例子吧!
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
$raw_name = $_GET['name'] ;
if(preg_match("/[A-Z | a-z]+/", $raw_name)){
$name=$raw_name;
////////////////////////////////////////
include "connect/connect.php";
//-query the database table
$sql="SELECT userId, Attribute, Name FROM government WHERE Name LIKE '%$name%' OR Attribute LIKE '%$name%' ORDER BY userid ASC";
///////////////////////// PAGINATION CLASS////////////////////////////////////
class Pagination {
public $current_page;
public $per_page;
public $total_count;
public function __construct($page=1, $per_page=20, $total_count=0){
$this->current_page = (int)$page;
$this->per_page = (int)$per_page;
$this->total_count = (int)$total_count;
}
public function offset() {
return ($this->current_page - 1) * $this->per_page;
}
public function total_pages() {
return ceil($this->total_count/$this->per_page);
}
public function previous_page() {
return $this->current_page - 1;
}
public function next_page() {
return $this->current_page + 1;
}
public function has_previous_page() {
return $this->previous_page() >= 1 ? true : false;
}
public function has_next_page() {
return $this->next_page() <= $this->total_pages() ? true : false;
}
}
///////////////////////////END OF PAGINATION CLASS///////////////////////////////
$curent_page = isset($_GET['page'])&&(int)$_GET['page'] !=0 ? (int)$_GET['page'] : 1 ;
$per_page = 7 ;
$sql = "SELECT COUNT(*) FROM government ";
$result = mysql_query($sql);
$total = mysql_result($result , 0);
$pagination = new Pagination($curent_page , $per_page , $total);
///////////////////////////////////////////////////////////////////////
//echo 'perpage : '.$pagination->per_page.'<br />';
//echo 'offset : '.$pagination->offset().'<br />';
///////////////////////////////////////////////////////////////////////
$rows_to_show = "SELECT userId, Attribute, Name FROM government WHERE Name LIKE '%$name%' OR Attribute LIKE '%$name%' LIMIT {$pagination->per_page} OFFSET {$pagination->offset()}";
if($pagination->total_pages() > 1){
echo '<div id="pagination_div">';
if($pagination->has_next_page()){
echo '<span><a href="search_govern.php?page='.$pagination->next_page();
echo '&name='.$name;
echo'" >> </a></span>' ;
}
for($i=1 ; $i <= $pagination->total_pages() ; $i++){
if($i == $pagination->current_page){
echo ' <strong>'.$i.' </strong>';
}
else {
echo '<span><a href="search_govern.php?page='.$i;
echo '&name='.$name;
echo'"> '.$i.' </a></span>';
}
}
if($pagination->has_previous_page()){
echo'<span><a href="search_govern.php?page='.$pagination->previous_page();
echo '&name='.$name;
echo'" > < </a></span>';
}
echo ' </div> ';
}
$dtotal = mysql_query($rows_to_show);
echo "$dtotal";
if ($dtotal === FALSE){ //////////// check to see if the query fails
die(mysql_error());
}
else{
//-create while loop and loop through result set
while($row=mysql_fetch_array($dtotal)){
$userId=$row['userId'];
$Attribute=$row['Attribute'];
$Name=$row['Name'];
//-display the result of the array
echo "<p style=\"margin:2px 0px 5px 0px;\" >";
echo "<p>" ."<a href=\"search_govern.php?id=$userId\"> " . $Name . "</a></p>";
echo "</p>";
}
}
}
else{
echo "<p> Please enter a search query</p>";
}
}
}
>
当你在$ pn = 2上回显$ limit时会发生什么? – 2012-04-21 21:55:08
你是什么意思? – JACrypto 2012-04-21 22:00:21
在声明$ limit var后放置一个“echo $ limit”语句。然后看看当你进入第二页时有什么回声($ pn = 2) – 2012-04-21 22:02:57