gpt4 book ai didi

javascript - 从 MySQL 数据加载滚动 jQuery/PHP 数据

转载 作者:行者123 更新时间:2023-11-30 01:10:25 26 4
gpt4 key购买 nike

下午好。我正在尝试实现上述目标,并一直遵循上述指南,请参阅@http://www.asif18.com/4/php/window-on-scroll-load-contents-in-php-mysql-using-jquery-bootstrap/

我创建的测试页面可以在这里看到。 http://coolnique.com/products_autoscroll.php

它看起来并不是坐着无所事事。当我访问“loadmore”页面时,它不会出错,所以可能是 javascript 不起作用?

这是我的js文件

$(document).ready(function(){   
$(window).scroll(function(){ /* window on scroll run the function using jquery and ajax */
var WindowHeight = $(window).height(); /* get the window height */
if($(window).scrollTop() +1 >= $(document).height() - WindowHeight){ /* check is that user scrolls down to the bottom of the page */
$("#loader").html("<img src='img/loading_icon.gif' alt='loading'/>"); /* displa the loading content */
var LastDiv = $(".project small:last"); /* get the last div of the dynamic content using ":last" */
var LastId = $(".project small:last").attr("id"); /* get the id of the last div */
var ValueToPass = "lastid="+LastId; /* create a variable that containing the url parameters which want to post to getdata.php file */
$.ajax({ /* post the values using AJAX */
type: "POST",
url: "_loadmore.php",
data: ValueToPass,
cache: false,
success: function(html){
$("#loader").html("");
LastDiv.after(html); /* get the out put of the getdata.php file and append it after the last div using after(), for each scroll this function will execute and display the results */
}
});
}
});
});

这是我加载更多文件...

<?php

//include location select
include'_locationselect.php';

// Connect to database

// HAVE REMOVE DATABASE VARIABLES FROM HERE

//Find last record

if(isset($_POST["lastid"]) && $_POST["lastid"] != "0"){
$lastid = $_POST["lastid"]; // save the posted value in a variable


$query="SELECT * FROM products WHERE product_price_$setLocation IS NOT NULL and product_id < '$lastid' Order By product_id DESC LIMIT 10";

$result=mysql_query($query) or die('Invalid query: ' .mysql_error());

// Store number of products as variable
$num=mysql_num_rows($result);

// Start loop to display products
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"product_name");
$f2=mysql_result($result,$i,"product_price_$setLocation");
$f3=mysql_result($result,$i,"product_link_$setLocation");
$f4=mysql_result($result,$i,"product_image");
// $f5=mysql_result($result,$i,"category_id");
// $f6=mysql_result($result,$i,"product_desc");
$f7=mysql_result($result,$i,"product_id");
$f1spacesremoved = str_replace(' ', '_', $f1);
if ($setLocation=="us")
{
$currencysymbol = "$";
}
else
{
$currencysymbol = "£";
};


//Write each product
//loop the text below
echo '<div class="project small" id="'.$f7.'">
<div class="inside">
<a href="/product/' .rawurlencode($f1spacesremoved). '/' .$f7. '">
<img width="300" height="175" src="/img/products/'.$f4.'" class="thumb wp-post-image" />
<span class="title"><span>'.$f1.'</span><span>'.$currencysymbol.' '.$f2.'</span></span>
</a>
</div> </div>

';
// Repeat loop until finished
$i++;
}
}
?>

然后在我的主页上有这段代码应该加载

                $query="SELECT * FROM products WHERE product_price_$setLocation IS NOT NULL Order By product_id DESC LIMIT 20";

$result=mysql_query($query) or die('Invalid query: ' .mysql_error());

// Store number of products as variable
$num=mysql_num_rows($result);

// Start loop to display products
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"product_name");
$f2=mysql_result($result,$i,"product_price_$setLocation");
$f3=mysql_result($result,$i,"product_link_$setLocation");
$f4=mysql_result($result,$i,"product_image");
// $f5=mysql_result($result,$i,"category_id");
// $f6=mysql_result($result,$i,"product_desc");
$f7=mysql_result($result,$i,"product_id");
$f1spacesremoved = str_replace(' ', '_', $f1);
if ($setLocation=="us")
{
$currencysymbol = "$";
}
else
{
$currencysymbol = "£";
};


//Write each product
//loop the text below
echo '<div class="project small" id="'.$f7.'">
<div class="inside">
<a href="/product/' .rawurlencode($f1spacesremoved). '/' .$f7. '">
<img width="300" height="175" src="/img/products/'.$f4.'" class="thumb wp-post-image" />
<span class="title"><span>'.$f1.'</span><span>'.$currencysymbol.' '.$f2.'</span></span>
</a>
</div> </div>

';
// Repeat loop until finished
$i++;
}
?>
<div id="loader"></div>
<div id="divResult"></div> <!-- here the rest of contents will display dynamically -->
</div>
</div>
</div>
</div>
</div>

任何指示都会有很大的帮助,因为我似乎无法让这个东西工作!我对 PHP 有点陌生!

最佳答案

loadmore.js -

尝试更改loadmore.js :1

$(document).ready(function(){   

jQuery(function($) {

关于javascript - 从 MySQL 数据加载滚动 jQuery/PHP 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19495470/

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