如何在无限滚动页面中对fetch_array使用多个SQL请求

时间:2019-04-24 12:32:08

标签: php

我在自己的网站上工作,该网站具有下载历史记录系统以及新产品检测系统。问题是,最近我使用以下视频将页面功能更改为具有无限滚动的页面:https://www.youtube.com/watch?v=XRAlEbVL8vQ。因此,我必须确保使用fetch_array更改系统,以使我的历史记录和新产品系统再次正常工作。

这是我的历史记录和新产品的旧系统。


$query = $data_base->prepare("SELECT product FROM history_textures WHERE id = :id AND page = :page AND product = :product AND download_date = ( SELECT MAX(download_date) FROM history_textures WHERE id = :id AND page = :page AND product = :product) ");
$query->bindParam(":id", $parameter_id, PDO::PARAM_INT);
$query->bindParam(":page", $parameter_page, PDO::PARAM_INT);
$query->bindParam(":product", $parameter_product, PDO::PARAM_INT);

$parameter_id = $id;
$parameter_page = $page;
$parameter_product = 1;

if($query->execute()) {
  if($query->rowCount() == 1) {
    if($user = $query->fetch()) {
      $product1 = $user["product"];
    }
  }
}

if(isset($product1)) {
$history_product1 = '<img class="validate" src="../Logos/Validate.png">';
}

$query = $data_base->prepare("SELECT creation_date FROM textures WHERE reference = :reference");
$query->bindParam(":reference", $parameter_reference, PDO::PARAM_STR);

$parameter_reference = "t1p".$page;

if($query->execute()) {
  if($query->rowCount() == 1) {
    if($user = $query->fetch()) {
      $date_start_product1 = $user["creation_date"];
    }
  }
}

if(isset($date_start_product1)) {
  $date_end_product1 = date('d-m-Y',strtotime($date_start_product1 . "+8 days"));

  $date = date('d-m-Y');
  $date=date('d-m-Y', strtotime($date));

  $date_start = date('d-m-Y', strtotime($date_start_product1));
  $date_end = date('d-m-Y', strtotime($date_end_product1));

  if (($date > $date_start) && ($date < $date_end)){
      $new_product1 = "NEW";
  }
}

Here is My new page system without history systems.

if (isset($_POST['getData'])) {

$conn = new mysqli('localhost', 'root', '', 'textures');

$start = $conn->real_escape_string($_POST['start']);
$limit = $conn->real_escape_string($_POST['limit']);

$sql = $conn->query("SELECT reference, name FROM textures ORDER BY reference DESC LIMIT $start, $limit");
if ($sql->num_rows > 0) {
  $response = "";

while($data = $sql->fetch_array()) {
    $response .=

'
<div id="textures">
  <div class="product">
    <p class="name">'.$data['name'].'</p>
    <a href="../Textures/product'.$data['reference'].'.php">
    <img class="preview" src="../Contents/Textures/Product'.$data['reference'].'/Preview/1.png" alt="Diamond Plate Textures" onContextMenu="return false;">
    </a>
    </div>
</div>
';

}

    exit($response);
} else
    exit('reachedMax');
}

我想找回$ data_reference,因此我可以在下面添加我的代码,因为我不能使用“ if”等条件。


$query = $data_base->prepare("SELECT product FROM history_textures WHERE id = :id AND product = :product AND download_date = ( SELECT MAX(download_date) FROM history_textures WHERE id = :id AND product = :product) ");
$query->bindParam(":id", $parameter_id, PDO::PARAM_INT);
$query->bindParam(":product", $parameter_product, PDO::PARAM_INT);

$parameter_id = $id;
$parameter_product = $data['reference'];

if($query->execute()) {
  if($query->rowCount() == 1) {
    if($user = $query->fetch()) {
      $product.$data['reference'] = $user["product"];
    }
  }
}

if(isset($product.$data['reference'])) {
$history_product.$data['reference'] = '<img class="validate" src="../Logos/Validate.png">';
}

$query = $data_base->prepare("SELECT creation_date FROM textures WHERE reference = :reference");
$query->bindParam(":reference", $parameter_reference, PDO::PARAM_INT);

$parameter_reference = $data['reference'];

if($query->execute()) {
  if($query->rowCount() == 1) {
    if($user = $query->fetch()) {
      $date_start_product.$data['reference'] = $user["creation_date"];
    }
  }
}

if(isset($date_start_product.$data['reference'])) {
  $date_end_product.$data['reference'] = date('d-m-Y',strtotime($date_start_product.$data['reference'] . "+8 days"));

  $date = date('d-m-Y');
  $date=date('d-m-Y', strtotime($date));

  $date_start = date('d-m-Y', strtotime($date_start_product.$data['reference']));
  $date_end = date('d-m-Y', strtotime($date_end_product.$data['reference']));

  if (($date > $date_start) && ($date < $date_end)){
      $new_product.$data['reference'] = "NEW";
  }
}

0 个答案:

没有答案