下一张和上一张图片

时间:2014-07-03 00:08:38

标签: php image mysqli hyperlink

我有两个链接,下一个和上一个,除了大于或小于下一个链接的相反方向的符号之外,代码是相同的。

还在努力解决这个问题,有人可以帮忙吗?

这是错误

您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在“ORDER BY photo_id DESC LIMIT 1”附近使用正确的语法UNION(选择photo_id FROM userphotos WHERE pho'在第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> | ";

1 个答案:

答案 0 :(得分:0)

从顶部开始:

<?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指的是$ photo_query,指的是$ mysqli。所以它就死了。

相关问题