Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php-mysql中的数据限制_Php_Mysql_Limit - Fatal编程技术网

php-mysql中的数据限制

php-mysql中的数据限制,php,mysql,limit,Php,Mysql,Limit,我做了一个slambook,它还在建造中。 我编写了以下代码: <?php $n=$_REQUEST['n']; $n=strtolower($n); echo "<html><body alink=black vlink=black link=black><center><h1>"; $target_dir = "fu/uploads/"; $target_file = $target_dir . $n . ".jpg"; if (file

我做了一个slambook,它还在建造中。 我编写了以下代码:

<?php
$n=$_REQUEST['n'];
$n=strtolower($n);
echo "<html><body alink=black vlink=black link=black><center><h1>";
$target_dir = "fu/uploads/";
$target_file = $target_dir . $n . ".jpg";
if (file_exists($target_file)) {
echo "<img src=\"http://slambook.esy.es/fu/uploads/".$n.".jpg\" width=85 height=85 alt=\"Profile Pic\">";
}
echo "Welcome to your wall, ".$n."</h1><br><br>";
echo "<a href=\"http://slambook.esy.es/passchangeh.php?n=".$n."\"><button>Change Password</button></a><br><br>";
echo "<form action=\"visit.php\" method=\"get\">";
echo "<input type=\"hidden\" name=\"u\" value=\"".$n."\">";
echo "<input type=\"text\" name=\"n\" placeholder=\"Search A Nickname\">";
echo "<input type=submit value=\"Search By Nickname\"></form>";
echo "<form action=\"sbi.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"u\" value=\"".$n."\">";
echo "<input type=\"text\" name=\"id\" placeholder=\"Search A id\">";
echo "<input type=submit value=\"Search By Id\"></form>";

$post="http://slambook.esy.es/post.php?n=".$n;
echo "<a href=".$post.">Fill Someone's Slambook</a><br><br><br>";
$servername = "myhost";
$username = "myusername";
$password = "mypass";
$dbname="mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT i,f,e,p,m,d FROM ".$n." ORDER BY i DESC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<center><table border=2><tr><th>Date</th><th>From</th><th>Email</th><th>Phone</th><th>Message</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $from=$row["f"];
        echo "<tr><td>".$row["d"]."</td><td><a href=\"http://slambook.esy.es/visit.php?n=".$from."\">".$from."</a></td><td>".$row["e"]."</td><td> ".$row["p"]."</td><td>".$row["m"]."</td></tr>";
    }
    echo "</table></center>";
} else {
    echo "Your slambook has been filled by 0 people!";
}
$conn->close();
?>

但在运行this wall.php时,所有记录都打印在一页上。 我想限制每页的数据量并使用分页系统。 我想要的是在桌子的末端, 一个“以前的文章”链接必须有,这将显示下一篇文章。 但我试了很多次,结果是:

<?php
$n=$_REQUEST['n'];
$p=$_REQUEST['p'];
$n=strtolower($n);

if($p=="")
$p=2;

$ipp=2;
$os=($p-1)*$ipp;

echo "<html><body alink=black vlink=black link=black><center><h1>";
$target_dir = "fu/uploads/";
$target_file = $target_dir . $n . ".jpg";
if (file_exists($target_file)) {
echo "<img src=\"http://slambook.esy.es/fu/uploads/".$n.".jpg\" width=85 height=85 alt=\"Profile Pic\">";
}
echo "Welcome to your wall, ".$n."</h1><br><br>";
echo "<a href=\"http://slambook.esy.es/passchangeh.php?n=".$n."\"><button>Change Password</button></a><br><br>";
echo "<form action=\"visit.php\" method=\"get\">";
echo "<input type=\"hidden\" name=\"u\" value=\"".$n."\">";
echo "<input type=\"text\" name=\"n\" placeholder=\"Search A Nickname\">";
echo "<input type=submit value=\"Search By Nickname\"></form>";
echo "<form action=\"sbi.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"u\" value=\"".$n."\">";
echo "<input type=\"text\" name=\"id\" placeholder=\"Search A id\">";
echo "<input type=submit value=\"Search By Id\"></form>";

$post="http://slambook.esy.es/post.php?n=".$n;
echo "<a href=".$post.">Fill Someone's Slambook</a><br><br><br>";
$servername = "myhost";
$username = "myuser";
$password = "mypass";
$dbname="mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM ".$n." ORDER BY id DESC LIMIT ".$os.",".$ipp."";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $page_count = (int)ceil($result / $ipp);
   // double check that request page is in range
   if($p > $page_count) {
        // error to user, maybe set page to 1
        $p = 1;
   }
    echo "<center><table border=2><tr><th>Date</th><th>From</th><th>Email</th><th>Phone</th><th>Message</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
    $from=$row["f"];
        echo "<tr><td>".$row["d"]."</td><td><a href=\"http://slambook.esy.es/visit.php?n=".$from."\">".$from."</a></td><td>".$row["e"]."</td><td> ".$row["p"]."</td><td>".$row["m"]."</td></tr>";

    }
    echo "</table></center>";
    echo "<a href=\"http://slambook.esy.es/betawall.php?n=".$n."&p=".($p+1)."\">Previous Posts</a>";
} else {
    echo "No more Posts";
}
$conn->close();
?>

但是在这个例子中,有5条记录,并且每页记录被设置为2,所以只有两页可见,第5条记录(应该在第3页)永远不会出现。
我应该怎么做才能修复此错误?

您可以使用更简单的分页,检查此项,并告诉我是否适用于您

由于隐私问题和改进的问题删除网站