Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.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
Javascript 如何通过php get请求实现分页_Javascript_Php - Fatal编程技术网

Javascript 如何通过php get请求实现分页

Javascript 如何通过php get请求实现分页,javascript,php,Javascript,Php,我有一些支持分页的代码,但我无法使我的按钮工作。有人能帮忙吗 function setData() { var flexContainer = document.getElementById("flex"); flexContainer.innerHTML = "<?php foreach ($articlesarray as $seperated) { $contentsContent = file_get_contents("../

我有一些支持分页的代码,但我无法使我的按钮工作。有人能帮忙吗

function setData() {
var flexContainer = document.getElementById("flex");
flexContainer.innerHTML = "<?php 
  foreach ($articlesarray as $seperated) {
    $contentsContent = file_get_contents("../" . "$seperated[contentsname]");
    echo "<div class='card'><img src='$seperated[img]'' alt='uh oh photo not found' style='width:100%''><div class='container'><h4><b>$seperated[title]</b></h4><p>$contentsContent</p></div></div>";
  }
 ?>";
document.getElementById("back").disabled = "<?php 
  if ($_SERVER['REQUEST_URI'] == "/list/index.php?page=1") {
    echo "true";
  } else {
    echo "false";
  }
?>";
document.getElementById("back").style = "<?php 
  if ($_SERVER['REQUEST_URI'] == "/list/index.php?page=1") {
    echo "display: none;";
  } else {
    echo "display: inline-block;";
  }
?>";
函数setData(){
var flexContainer=document.getElementById(“flex”);

flexContainer.innerHTML=“这是一个GET请求,所以在PHP中我可以直接使用它
$\u获取[“页面”]
,然后相应地加上或减去1。

“我无法使我的按钮工作。”"-这意味着什么?呈现的JS看起来像什么?有html可以将ot组合在一起。Php使用get请求来知道从表中获取哪些数据,该表作为localhost/list附加到url?page=1我希望分页能够检测到您所在的页面,并按照该页面进行操作代码长度为1302个字符,请查看这是js小提琴。看看光标分页
$servername = "localhost";
$username = "root";
$password = "You can't have my server password";
$dbname = "myDB";

$badurl = "/list/index.php";
$newURL = "/list/index.php?page=1";

if ($_SERVER['REQUEST_URI']==$badurl) {
  print "uh oh spaghettios";
  header('Location: ' . $newURL);
  die();
}

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$offsetAmount = $_GET["page"] * 9 - 9;

$sql = "SELECT id, title, contentsname, img FROM articles LIMIT 9 OFFSET $offsetAmount";
$result = $conn->query($sql);

$articlesarray = array();

while($row = mysqli_fetch_assoc($result)){
   $articlesarray[] = $row;
}

//echo "<br><br><br> If you are reading this, you have found the debug screen. This website is under maintanence.";

mysqli_close($conn);