简体   繁体   中英

Next and previous image

I have two links, next and previous, the code is identical other than the greater or less than symbols being in the opposite direction for the next link.

Still struggling with this, can anybody help?

This is the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY photo_id DESC LIMIT 1) UNION (SELECT photo_id FROM userphotos WHERE pho' at line 1

$id=$_SESSION['id'];
//Now we'll get the list of the specified users photos
$sql = "SELECT id FROM albums WHERE user_id='$id' ORDER BY name ASC LIMIT 1 ";
$query = mysqli_query($mysqli,$sql)or die(mysqli_error($mysqli));

while($album = mysqli_fetch_array($query)){ ?>

<?php
    $var = $_GET['pid'] ;
    $photo_sql = "(SELECT photo_id FROM userphotos WHERE photo_id < ".$var." AND photo_ownerid = ".$user['id']." AND album_id=".$album['id']." ORDER BY photo_id DESC LIMIT 1)";
    $photo_sql.= " UNION (SELECT photo_id FROM userphotos WHERE photo_id > ".$var." AND photo_ownerid = ".$user['id']." AND album_id=".$album['id']." ORDER BY photo_id DESC LIMIT 1)";
    $photo_query = mysqli_query($mysqli,$photo_sql)or die(mysqli_error($mysqli));
    $photo_prev=mysqli_fetch_array($photo_query);

            echo " <a href='photo.php?pid=".$photo_prev['photo_id']."'>Previous</a> | ";

Starting from the top:

<?php //this is the very first line
$mysqli = new mysqli($this->DBIP, $this->UName, $this->pw, $this->DB); //set mysqli
$sql = "SELECT id FROM albums WHERE user_id='$id' ORDER BY name ASC LIMIT 1 ";
//can't query $mysqli unless you set it to a connection.
$query = mysqli_query($mysqli,$sql)or die(mysqli_error($mysqli));
while($album = mysqli_fetch_array($query)){ // remove this --> "?>"

$photo_prev refers to $photo_query, refers to $mysqli. so it dies there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM