我搜索了大约75篇文章,但似乎没有一篇对我有用。
我在search-form.php中有一个搜索表单,允许用户搜索特定用户,结果显示在search.php中。从工作和结果显示没有问题,除了我有一个限制“10”设置和10显示在初始页面上,但当点击下一页的分页按钮时,它不会显示剩余的结果。
任何帮助我指向正确方向的人都将不胜感激。这不是一个实时服务器,我用它来学习php和mysql,所以除了你的普通php之外,我是新手。
search-form.php
代码:<form action="getdata.php" method="get">
<label>Name:
<input type="text" name="keyname" />
</label>
<input type="submit" value="Search" />
</form>
getdata.php
代码:<?php
$searchTerm = trim($_GET['keyname']);
if($searchTerm == "")
{
echo "Enter name you are searching for.";
exit();
}
$dbhost = 'localhost';
$dbuser = 'xxxxx';
$dbpass = 'xxxxx';
$rec_limit = 10;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('xxxxx_xxxxx');
$sql = "SELECT count(note_id) FROM notes ";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = ("SELECT * FROM notes WHERE emp_code LIKE '%$searchTerm%' LIMIT $offset, $rec_limit");
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "<ul data-role='listview' data-inset='true'>" .
"<li data-role='list-divider'>Friday, October 8, 2010 <span class='ui-li-count'>Note ID: {$row['note_id']}</span></li>" .
"<li><a href='#'>" .
"<p>Employee Code: {$row['emp_code']}</p>" .
"<p>Note: {$row['emp_note']}</p>" .
"</a></li></ul>";
}
if( $page > 0 )
{
$last = $page - 2;
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$last\">Last 10 Records</a> |";
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$page\">Next 10 Records</a>";
}
else if( $page == 0 )
{
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$page\">Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=$last\">Last 10 Records</a>";
}
mysql_close($conn);
?>
答案 0 :(得分:1)
您需要为GET使用方括号,而不是大括号。 if( isset($_GET{'page'} ) )
这是不正确的语法,并且无法正常工作。
if( isset($_GET['page'] ) )
{
$page = $_GET['page'] + 1;