gpt4 book ai didi

php - 非常奇怪的mysql php blog 发生

转载 作者:行者123 更新时间:2023-11-28 23:22:15 25 4
gpt4 key购买 nike

好的,我遇到的问题很奇怪。我有一个显示帖子列表的博客网站,我制作了一个系统,一次只能选择 10 个帖子。然而在第二个生成的页面上显示了 12 个结果(最后两个是重复的)

//删除了 url,因为问题已解决,我不想注入(inject) sql

如果你转到我上面的项目并查看帖子的第二页,会显示 12 个条目,最后 2 个条目与第 3(和最后)页重复...发生了什么事?!它们不应该出现,因为 sql LIMIT 函数应该将显示的帖子限制为 10。

这是主页.php 的代码

 <?php
session_start();
ob_start();

if ($_SERVER["REQUEST_METHOD"] == "POST"){//this works in my tests.
$low = 0;
$high = 10; //this loop/if method works in conjunction with the code at the bottom of this page
$e = 1;//starts at 1 because 1 itself is defined my default at the bottom of the page
while($_SESSION['i'] != $e){
$e++;

if (isset($_REQUEST["p$e"])){
$u = 1;
while($u != $e){
$u++;
$low = $low + 10;
$high = $high +10;
}


}
}}else{
$low = 0;
$high = 10;
}
?>
<!doctype html>
<!-- AUTHOR:JOSH FAIRBANKS -->
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home Page</title>
<link rel="stylesheet" href="style.css">


</head>

<body>
<nav>
<ul>
<li><a href = "addPost.php"><div id = "new">Create new post</div></a></li>
<li><a href = "mainPage.php"><div id = "veiw">Veiw posts</div></a></li>
</ul>
</nav>
<main>
<?php
$link = mysqli_connect( 'localhost', 'username', 'password' );
mysqli_select_db( $link, 'mydatabasename' );

$results = mysqli_query( $link, "SELECT LEFT(post, 575) as post FROM Users where verified = 1 ORDER BY `id` DESC LIMIT $low , $high" ); //this displayes all the posts that have been verified
while( $record = mysqli_fetch_assoc( $results ) ) {
$post = $record['post'];


$count = mysqli_affected_rows( $link );
//ORDER BY YEAR(Date) DESC, MONTH(Date) DESC, DAY(DATE) DESC
$post .= "</td></tr></table>";
print $post;


}
$vresults = mysqli_query( $link, "SELECT post FROM Users where verified = 1" );
while( $vrecord = mysqli_fetch_assoc( $vresults ) ) {
$vpost = $vrecord['post'];


$vcount = mysqli_affected_rows( $link );
$_SESSION['vcount'] = $vcount;
//
//these mirror variables arent seen and just are used to count the total amount of posts
//not just the ones on the page
}

mysqli_free_result( $results );
mysqli_close( $link );
?>
<form method = "post" action = "mainPage.php">
<table>
<tr><td>Page Number: </td><!--<td><input type = "submit" name = "p1" value = "1"></td>-->
<?php
$i = 0;
print "displaying low: $low high: $high";
for($j = 0; $j < $vcount; $j++) //modulus
{

if($j % 10 == 0)
{
$i++;
$_SESSION['i'] = $i;
print "<td><input type = 'submit' name ='"."p".$i. "' value = '$i'></td>";
}
}
?>
</tr>
</table>
</form>
</main>
</body>
</html>

我知道这段代码有点乱 :p 但我发誓除了这个令人沮丧的问题外它是有效的。任何帮助表示赞赏。

最佳答案

我猜你的问题在 $high 变量...每页记录总是不变的。但似乎你在一个地方增加了。

if ($_SERVER["REQUEST_METHOD"] == "POST"){//this works in my tests. 
$low = 0;
$high = 10; //this loop/if method works in conjunction with the code at the bottom of this page
$e = 1;//starts at 1 because 1 itself is defined my default at the bottom of the page
while($_SESSION['i'] != $e){
$e++;

if (isset($_REQUEST["p$e"])){
$u = 1;
while($u != $e){
$u++;
$low = $low + 10;
$high = 10;
}


}
}}else{
$low = 0;
$high = 10;
}
?>

关于php - 非常奇怪的mysql php blog 发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41053210/

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