gpt4 book ai didi

从 mysql 数据库中的 php 搜索只显示一页

转载 作者:行者123 更新时间:2023-11-29 00:46:41 25 4
gpt4 key购买 nike

下面的脚本只显示第一页和下一页的链接,但没有指向任何地方。有人能帮我吗?

$var = @$_GET['q'] ;
$trimmed = trim($var);
$limit = 10;

if ($trimmed == "")
{
echo "<p>What are you looking for?...</p>";
exit;
}

if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}

mysql_connect('xxx', 'yyy', 'zzz');
mysql_select_db('yyy') or die('Unable to select database');
$query = "select * from table where NAME like '%$trimmed%' order by NAME";
$numresults = mysql_query($query);
$numrows = mysql_num_rows($numresults);

if ($numrows == 0)
{
echo "<h4>Results</h4>";
echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";
echo "<p><a href=\"http://www.google.com/search?q="
. $trimmed . "\" target=\"_blank\" title=\"Look up
" . $trimmed . " on Google\">Click here</a> to try the search on google</p>";
}

if (empty($s))
{
$s = 0;
}

$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";
echo "Results";
$count = 1 + $s;

while ($row= mysql_fetch_array($result))
{
$title = $row["NAME"];
echo "$count.-&nbsp;$title" ;
$count++ ;
}

$currPage = (($s/$limit) + 1);
echo "<br />";

if ($s >= 1)
{
// bypass PREV link if s is 0
$prevs = ($s - $limit);
print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
Prev 10</a>&nbsp;";
}

$pages = intval($numrows/$limit);

if ($numrows % $limit)
{
$pages++;
}

if (!((($s+$limit)/$limit) == $pages) && $pages != 1)
{
$news = $s + $limit;
print "<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
}

$a = $s + ($limit);

if ($a > $numrows)
{
$a = $numrows;
}

$b = $s + 1;
echo "<p>Showing results $b to $a of $numrows</p>";

最佳答案

在您的代码中,每次重新加载页面或单击下一页链接时,$s 都会重置。您的代码开头应该有 $s = $_REQUEST['s']

关于从 mysql 数据库中的 php 搜索只显示一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10265472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com