gpt4 book ai didi

PHP分页问题

转载 作者:行者123 更新时间:2023-11-29 14:47:17 25 4
gpt4 key购买 nike

我搜索了很多网站并尝试了网上提供的不同方法,但它不起作用。当我单击下一个、最后一个、第一个、上一个时,它不会加载信息。它只加载第一页的结果。请帮忙!预先感谢您。

function retrieveName($fieldName)
{
$i=1;
if(isset($_GET[$fieldName]))
{
mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db("intern") or die(mysql_error());


//This checks to see if there is a page number. If not, it will set it to page 1

if (!(isset($pagenum)))

{

$pagenum = 1;

}

//Here we count the number of results

$intern = $_GET[$fieldName];
$data = mysql_query("SELECT p.`internName`, p.`internNRIC`, c.`internSchName` FROM `personaldetails` p, `currentinstitution` c WHERE c.`internNRIC`= p.`internNRIC` AND p.`internName` like '%$intern%' || p.`internNRIC` like '%$intern%' || c.`internSchName` like '%$intern%' GROUP BY p.internNRIC") or die(mysql_error());

$rows = mysql_num_rows($data);

//This is the number of results displayed per page

$page_rows = 1;


//This tells us the page number of our last page

$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages

if ($pagenum < 1)

{

$pagenum = 1;

}

elseif ($pagenum > $last)

{

$pagenum = $last;

}

//This sets the range to display in our query

$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;

PRODUCTION. //This is your query again, the same one... the only difference is we add $max into it

$data_p = mysql_query("SELECT p.`internName`, p.`internNRIC`, c.`internSchName` FROM `personaldetails` p, `currentinstitution` c WHERE c.`internNRIC`= p.`internNRIC` AND p.`internName` like '%$intern%' || p.`internNRIC` like '%$intern%' || c.`internSchName` like '%$intern%' GROUP BY p.internNRIC $max ") or die(mysql_error());


//This is where you display your query results

while($row = mysql_fetch_array( $data_p ))
{
echo $i. ".";
echo " NRIC : <a href='InternInfo.php?id='" . $row['internNRIC'] . ">".$row['internNRIC'] ."</a>";
echo "</br><br/>";
echo " Name : ". $row['internName'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name of School :" . $row['internSchName'];
echo "</br><br/>";
$i++;
}

echo "<p>";


// This shows the user what page they are on, and the total number of pages

echo " --Page $pagenum of $last-- <p>";


// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.

if ($pagenum == 1)

{

}

else

{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&searchIntern=$intern'> <<-First</a> ";
echo "---Interns Search---";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&searchIntern=$intern'> <-Previous</a> ";

}

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links

if ($pagenum == $last)

{

}

else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&searchIntern=$intern'>Next -></a> ";
echo "---Interns Search---";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&searchIntern=$intern'>Last ->></a> ";

}
}else echo "Please enter your search.";
}

最佳答案

对此不是 100%,但看起来您正在使用 $pagenum 的局部变量当您想使用参数(好主意)或全局变量(例如 $_GET['pagenum'])时。您还让自己面临 SQL 注入(inject)的风险。对查询中需要使用的所有变量(例如 $intern)使用 mysql_real_escape_string。

关于PHP分页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6673513/

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