我有两个链接,下一个和上一个,除了大于或小于下一个链接的相反方向的符号之外,代码是相同的。
还在努力解决这个问题,有人可以帮忙吗?
这是错误
您的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> | ";
答案 0 :(得分:0)
我会做这个查询...
$qry = "SELECT photo_id FROM userphotos WHERE ( photo_id < ".$var." OR photo_id > ".$var." ) AND photo_ownerid = ".$user['id']." AND album_id=".$album['id']." ORDER BY photo_id DESC LIMIT 1";
而且,正如Bartdude所说,检查var是否为空或其他......