我的图像问题应该像分页中的下一个按钮一样。在此页码上,next和previus按钮工作正常。
我希望能够点击图片" Naprijed.png
"它应该将我重定向到" smartphone?page=2
"。当页面为" smartphone?page=2
"时,请点击图片" Naprijed.png"应该将我重定向到" smartphone?page=3
"等
这是否可能以我想要的方式进行?
<html>
<body>
<div id="container">
<?php
// 5. record shown amount
$per_page = 10;
// 7. current page
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// 4. mysql start possition
if ($page <= 1) {
$start = 0;
} else {
$start = $page * $per_page - $per_page;
}
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY id ASC ";
$num_rows = mysqli_num_rows(mysqli_query($con, $query));
$num_pages = ceil($num_rows / $per_page);
?>
<div id="natrag">
<img src="Okviri/Natrag.png" width="70" height="70" alt="Natrag" onclick="goBack()" onmouseover="" style="cursor: pointer;">
<script>
function goBack() {
window.history.back();
}
</script>
<?php echo '<a class="two" href=index><img src="Okviri/home.png" width="70px" height="70px" onmouseover="" style="cursor: pointer;"></a>'; ?>
<img src="Okviri/Naprijed.png" width="70" height="70" alt="Naprijed" onclick="goForward()" onmouseover="" style="cursor: pointer;">
<script>
function goForward() {
window.location.href = "smartphone?page=$next";
}
</script>
</div>
<div id="pagination">
<?php
$prev = $page - 1;
$next = $page + 1;
$order = isset($_GET['order']) ? $_GET['order'] : '';
// prev
if ($prev > 0) {
echo "<a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$prev&order=$order'><b><</b></a> ";
}
//numbers
$number = 1;
for ($number; $number <= $num_pages; $number +=1) {
if ($page == $number) {
echo " <b style='font-size:30px; color: #099BCD;'> $number </b> ";
} else {
echo " <a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$number&order=$order'>$number</a> ";
}
}
// next
if ($page < ceil($num_rows / $per_page)) {
echo " <a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$next&order=$order'><b>></b></a> ";
}
?>
</div>
<div id="gumb">
<div id="usporedivanje">
<input type='submit' form='Forma' name='usporedi' disabled='disabled' id='usporedi' value='Usporedi' onmouseover="" style="cursor: pointer;" />
<div id='sortiranje'>
<select id='filter' style="font-size:20px; height:50px; border: 5px solid #099CDB; border-radius: 10px; border-color: #099bcd;" name="filter" onchange="window.location.href = 'smartphone?order=' + this.value">
<option>Poredaj po: </option>
<option value="naziv">Naziv</option>
<option value="cijenaasc">Cijena Manja-Veća</option>
<option value="cijenadesc">Cijena Veća-Manja</option>
</select>
</div>
</div>
<br/>
<form id="Forma" method='post'>
<?php
$order = isset($_GET['order']) ? $_GET['order'] : '';
if ($order) {
switch ($order) {
case 'cijenaasc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY CAST(cijena AS DECIMAL(8,2)) ASC ";
break;
case 'naziv':
$order = 'naziv';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY naziv ASC ";
break;
case 'cijenadesc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY CAST(cijena AS DECIMAL(8,2)) DESC ";
break;
}
}
$query .= " LIMIT $start, $per_page";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$id = $row ['id'];
print
"<div id='proizvod'></br><a style='text-decoration:none; color:black; font-size:20px;' class='two' href='proizvod.php?id=$id' ><b>" . $row["naziv"] . "</b>" .
"<p><img src=" . $row["slika"] . " width='200px' height='200px' style='border-radius: 15px;'></p>" .
"<p style='font-size:20px'><b> Cijena za gotovinu: " . $row["cijena"] . " KN </b></p>" .
"<pre id='pre1'>" . $row["opis"] . "</pre>" .
"</a></div>";
}
?>
</form>
</div>
</div>
<?php include "footer.php"; ?>
</body>
</html>
答案 0 :(得分:1)
目前,在goForward
功能中,您有以下代码:
window.location.href = "smartphone?page=$next";
这不起作用。您可以将$next
放在PHP字符串中,但在PHP标记之外它只会被忽略。您可以通过将其放在PHP标记中来解决此问题:
window.location.href = "smartphone?page=<?php echo $next;?>";
编辑:此外,您在此代码之后定义了$ next变量。所以你需要提高它。