【发布时间】:2018-04-12 06:41:21
【问题描述】:
这是一个简单的分页尝试。以为我会按照我所知道的去做。现在页面运行良好,我可以滚动浏览LIMIT $startfrom、$displayto(amount)
问题是第一页显示图像,但是一旦我单击按钮浏览图像,我就没有图像?但是当我点击返回时,我会这样做,但只有 3 个。
我真的不确定发生了什么,但分页结果应该是这样(0-5 , 5-5, 10,5 15,5 20,5) 等。但是在 0,5 之后 - 没有更多图像了。
我也通过FORM 发布$variables。
另外,当我浏览 DEV 时,我发现动态图像在第一页之后不存在。但是 LIMIT 是正确的,应该会按预期显示,只是由于某些奇怪的原因没有图像。我认为它与手动调用 MYSQ 以再次运行数据库有关,但我不确定为什么它不会通过 FORM POST 执行此操作,因为它会调用整个脚本和页面。
<?php
//
include ("conect.php");
if (isset($_POST['startfrom'])) {
$startfrom = htmlentities($_POST['startfrom'] ); };
if (isset($_POST['displayto'])) {
$displayto = htmlentities($_POST['displayto'] ); };
if (isset($_POST['resultcheck'])) {
$resultcheck = htmlentities($_POST['resultcheck'] ); };
if (isset($_POST['maxresults'])) {
$maxresults = htmlentities($_POST['maxresults'] ); };
if (empty($maxresults)) {$maxresults=5; }
if (empty($startfrom)) {$startfrom=0; };
if (empty($displayto)) {$displayto=5; };
if (empty($resultcheck)) {$resultcheck=0; };
if (!empty($resultcheck)) {$resultcheck=$resultcheck; };
if (!empty($startfrom)) {$startfrom=$startfrom; };
if (!empty($displayto)) {$displayto=$displayto; };
if (!empty($maxresults)) {$maxresults=$maxresults; }
if (isset($_POST['searchfor'])) {
$search = htmlentities($_POST['searchfor'] ); }
function ($search) {
echo htmlspecialchars($search, ENT_QUOTES, 'utf-8');
};
$search = mysqli_real_escape_string($conn, $search);
$search = filter_var($search, FILTER_SANITIZE_STRING);
if (empty($search)) { $search="";};
if (isset($_POST['location'])) {
$location = htmlentities($_POST['location'] ); }
function ($location) {
echo htmlspecialchars($location, ENT_QUOTES, 'utf-8');
};
$location = mysqli_real_escape_string($conn, $location);
$location = filter_var($location, FILTER_SANITIZE_STRING);
//$location = strtolower($location);
if (empty($location)) { $location="";};
if (isset($_POST['postcode'])) {
$postcode = htmlentities($_POST['postcode'] ); }
function ($postcode) {
echo htmlspecialchars($postcode, ENT_QUOTES, 'utf-8');
};
$postcode = mysqli_real_escape_string($conn, $postcode);
$postcode = filter_var($postcode, FILTER_SANITIZE_STRING);
if (empty($postcode)) { $postcode="";};
if (isset($_POST['price'])) {
$price = htmlentities($_POST['price'] ); }
function ($price) {
echo htmlspecialchars($price, ENT_QUOTES, 'utf-8');
};
$price = mysqli_real_escape_string($conn, $price);
$price = filter_var($price, FILTER_SANITIZE_STRING);
if (empty($price)) { $price="";};
if (isset($_POST['catagory'])) {
$catagory = htmlentities($_POST['catagory'] ); }
function ($catagory) {
echo htmlspecialchars($catagory, ENT_QUOTES, 'utf-8');
};
$catagory = mysqli_real_escape_string($conn, $catagory);
$catagory = filter_var($catagory, FILTER_SANITIZE_STRING);
if (empty($catagory)) {$catagory="";};
if ($resultcheck<1) {
if (empty($postcode)) {
if (!empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND title LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate='$location' AND title LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate LIKE '%%$location%%' AND type LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate='$location' AND type LIKE '%%$search%%'
";
};
if (empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' OR locate ='%%$location%%' ORDER BY price DESC
";
};
if (empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' ORDER BY price DESC
";
};
if (!empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND title LIKE '%%$search%%' OR info LIKE '%%$search%%' ORDER BY price DESC
";
};
};
if (!empty($postcode)) {
if (!empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='$location' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate LIKE '%%$location%%' AND type LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='$location' AND type LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
ORDER BY price DESC
";
};
if (empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='%%$location%%' AND postcode LIKE '%%$postcode%%'
ORDER BY price DESC
";
};
if (empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND postcode LIKE '%%$postcode%%' OR postcode='%%$postcode%%'
ORDER BY price DESC
";
};
if (!empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR info LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
ORDER BY price DESC
";
};
};
$result = $conn->query($sql);
$row_cnt = $result->num_rows;
$maxresults=$row_cnt;
$resultcheck="1";
}; //if empty resultcheck
if ($resultcheck=1 OR $resultcheck>1) {
if (empty($postcode)) {
if (!empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND title LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate='$location' AND title LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate LIKE '%%$location%%' AND type LIKE '%%$search%%'
OR price LIKE '%%$price%%' AND locate='$location' AND type LIKE '%%$search%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
if (empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' OR locate ='%%$location%%' ORDER B price DESC LIMIT $startfrom,$displayto
";
};
if (empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
if (empty($location) && !empty($search))";
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND title LIKE '%%$search%%' OR info LIKE '%%$search%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
};
if (!empty($postcode)) {
if (!empty($search) && !empty($location)) {
//echo "1. if (!empty($search) && !empty($location)) ";
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='$location' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate LIKE '%%$location%%' AND type LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='$location' AND type LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
if (empty($search) && !empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND locate LIKE '%%$location%%' AND postcode LIKE '%%$postcode%%'
OR price LIKE '%%$price%%' AND locate='%%$location%%' AND postcode LIKE '%%$postcode%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
if (empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND postcode LIKE '%%$postcode%%' OR postcode='%%$postcode%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
if (!empty($search) && empty($location)) {
$sql = "SELECT * FROM testdata
WHERE price LIKE '%%$price%%' AND type LIKE '%%$catagory%%' AND title LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%'
OR info LIKE '%%$search%%' AND postcode LIKE '%%$postcode%%' ORDER BY price DESC LIMIT $startfrom,$displayto
";
};
};
$result = $conn->query($sql);
$resultcheck=2;
};
echo" <div class='searchresults'> ";
printf("Search Results for {$search} in {$catagory} Within {$location} & Totals %d results {$displayto}&{$startfrom} <br><br>", $maxresults);
echo" </div>";
while($row = mysqli_fetch_assoc($result)) { // while($row = mysqli_fetch_assoc($result)) {
$vid = $row['id']; //<!---important is Video ID and needed for video click selection---->
$type = $row['type'];
$id = $row['id'];
$vidd= $row['id']-0.01;
$pidd= $row['id']-0.02;
$name = $row['Name'];
$image = $row['image'];
$info = $row['info'];
$phone = $row['phone'];
$title = $row['title'];
$locate = $row['locate'];
$postcoded = $row['postcode'];
$price = $row['price'];
$videos = $row['videos'];
$date = $row['stamp'];
$type = $row['type'];
$showinglocate=$row['id']-0.03;
$showingphone=$row['id']-0.04;
echo"
<div class='floater'>
<div style='position:absolute; top:0%; left:0%; width:100%; height:99%; border-radius: 1vw; box-shadow: 1px 1px 3px 1px #aaa; background-color:white; overflow:hidden;'>
";
if (empty($videos) && empty($image)) {
echo "<img src='image/blank.png' style='position:absolute; top:18%; left:10%; width:80%; height:68%; opacity:0.5; transform: scale(1.0,1.1);'>
"; }
if (!empty($videos)) {
echo "
<video id='$vidd' title='{$row['title']} {$row['locate']}' style='position:absolute; top:18%; left:0%; width:100%; height:60%; transform: scale(1.0,1.1);' preload='metadata' controls='controls'>
<source src='vid/{$row['videos']}.mp4' type='video/mp4'>
<source src='vid/{$row['videos']}.mp4' type='video/ogg'>
<source src='vid/{$row['videos']}.mp4' type='video/webm'>
</video >
<div id='vidicon' title='Video's' class='vidicon' ondblclick='controlshowvid($vidd , $pidd);' ><img src='pageimages/vidicon.jpg' style='position:absolute; top:0%; left:0%; width:100%; height:100%; z-index:1; cursor:hand;'></div>
"; }
if (!empty($image)) {
echo "<img id='$pidd' src='image/{$row['image']}' style='position:absolute; top:18%; left:0%; width:100%; height:60%; transform: scale(1.0,1.1);'>
<div id='pictureicon' title='Pictures' class='pictureicon' ondblclick='controlshowimage($vidd , $pidd);'><img src='pageimages/pictureicon.jpg' style='position:absolute; top:0%; left:0%; width:100%; height:100%; z-index:1; cursor:hand;'></div>
"; }
echo "
<div id='displaytitle' style='position:absolute; top:3%; left:1%; width:100%;'><font style='font-size:1.4em;color:blue'><center>{$row['title']}</center></div></font>
<div id='displaystamp' title='{$row['stamp']}'style='position:absolute; top:9.0%; left:3%; width:30%; text-align:left;'><font style='color:grey; font-size:0.6em;'>{$row['stamp']}</div><br></font>
<div id='displaypostcode' title='{$row['postcode']}' style='position:absolute; top:9%; left:84.8%; width:16.2%; '><font style='color:grey; font-size:0.7em;'>{$row['postcode']}</div><br></font>
<div id='displayprice' style='position:absolute; top:90%; left:2%; text-align:center; border-radius: 1vw; box-shadow: 1px 1px 2px 1px #aaa;'><font style='color:blue;'><center><strong>£{$row['price']}</strong></center></div>
<div id='$showinglocate' title='{$row['postcode']}' style='position:absolute; top:82%; left:0%; width:100%; Z-index:15; cursor:hand;' ondblclick='changeshowdetail($showinglocate, $showingphone)' ><font style='color:black'><center><strong>{$row['locate']}</strong></center></div>
<div id='$showingphone' title='{$row['Name']}' style='position:absolute; top:82%; left:0%; width:100%; visibility:hidden; cursor:hand; ' ondblclick='changeshowdetail2($showinglocate,$showingphone)' ><font style='color:black'><center><strong>{$row['phone']}</strong></center></div>
<div id='showwhole' class='showwhole' title='Click to View' ondblclick='' ><font style='font-size:0.8em; #ddd'>View Full Page</font></div>
</div>
</div>
";
}
?>
</div>
</div>
</div>
<div class="footer">
<form id='sendpaginationforward' action='linkdsearch.php' method='POST' enctype='multipart/form-data' >
<input type='hidden' type='text' name='startfrom' value='<?php echo $startfrom = $startfrom +5 ?>' />
<input type='hidden' type='text' name='displayto' value='<?php echo $displayto = 5 ?>' />
<input type='hidden' type='text' name='searchfor' value='<?php echo $search ?>' />
<input type='hidden' type='text' name='price' value='<?php echo $price ?>' />
<input type='hidden' type='text' name='catagory' value='<?php echo $catagory ?>' />
<input type='hidden' type='text' name='location' value='<?php echo $location ?>' />
<input type='hidden' type='text' name='resultcheck' value='<?php echo $resultcheck ?>' />
<input type='hidden' type='text' name='postcode' value='<?php echo $postcode ?>' />
<input type='hidden' type='text' name='maxresults' value='<?php echo $maxresults ?>' />
<input type='hidden' type='submit' value='submit'>
</form>
<form id='sendpaginationback' action='linkdsearch.php' method='POST' enctype='multipart/form-data' >
<input type='hidden' type='text' name='startfrom2' value='<?php echo $startfrom = $startfrom -5 ?>' />
<input type='hidden' type='text' name='displayto2' value='<?php echo $displayto = 5 ?>' />
<input type='hidden' type='text' name='searchfor' value='<?php echo $search ?>' />
<input type='hidden' type='text' name='price' value='<?php echo $price ?>' />
<input type='hidden' type='text' name='catagory' value='<?php echo $catagory ?>' />
<input type='hidden' type='text' name='location' value='<?php echo $location ?>' />
<input type='hidden' type='text' name='resultcheck' value='<?php echo $resultcheck ?>' />
<input type='hidden' type='text' name='postcode' value='<?php echo $postcode ?>' />
<input type='hidden' type='text' name='maxresults' value='<?php echo $maxresults ?>' />
<input type='hidden' type='submit' value='submit'>
</form>
<img src="pageimages/pictureicon.jpg" ondblclick="changeamountdisplay2();" style='position:absolute; left:20%;'>
<img src="pageimages/vidicon.jpg" ondblclick="changeamountdisplay();" style='position:absolute; left:80%;'>
<p> display<?php echo $displayto; ?> </p>
<p> start from<?php echo $startfrom; ?> </p>
<p> max<?php echo $maxresults; ?> </p>
<p> check<?php echo $resultcheck; ?> </p>
</div>
</div>
<script>
function changeamountdisplay(){
document.getElementById('sendpaginationforward').submit(); return false;
};
</script>
<script>
function changeamountdisplay2(){
document.getElementById('sendpaginationback').submit(); return false;
};
</script>
<script type="text/javascript">
function changeshowdetail(showinglocate,showingphone)
{
document.getElementById(showinglocate).style.opacity=('0.0');
document.getElementById(showinglocate).style.visibility=('hidden');
document.getElementById(showinglocate).style.Zindex=('-1');
document.getElementById(showingphone).style.opacity=('1.1');
document.getElementById(showingphone).style.Zindex=('10');
document.getElementById(showingphone).style.visibility=('visible');
};
function changeshowdetail2(showinglocate,showingphone)
{
document.getElementById(showingphone).style.opacity=('0.0');
document.getElementById(showingphone).style.Zindex=('-1');
document.getElementById(showingphone).style.visibility=('hidden');
document.getElementById(showinglocate).style.opacity=('1.1');
document.getElementById(showinglocate).style.visibility=('visible');
document.getElementById(showinglocate).style.Zindex=('10');
};
</script>
<script>
function controlshowvid(vidd,pidd){
document.getElementById(pidd).style.opacity=('0.0');
document.getElementById(pidd).style.visibility=('hidden');
document.getElementById(vidd).style.opacity=('1.1');
document.getElementById(vidd).style.Zindex=('15');
document.getElementById(pidd).style.Zindex=('-1');
};
function controlshowimage(vidd,pidd){
document.getElementById(vidd).style.opacity=('0.0');
document.getElementById(pidd).style.opacity=('1.1');
document.getElementById(pidd).style.visibility=('visible');
document.getElementById(vidd).style.Zindex=('-1');
document.getElementById(pidd).style.Zindex=('15');
};
</script>
</body>
</html>
事实上,想想看,我最好只做一个图像滚动而不是分页。我会调查一下。但我绝对想知道如何完成分页。但是,如果有人可以提供简单的图像旋转,我会非常满意。
【问题讨论】:
标签: javascript php mysql pagination limit