2014-07-03 50 views
0

我有兩個鏈接,下一個和上一個,代碼是相同的,除了大於或小於符號在下一個鏈接的相反方向。下一個和上一個圖像

仍在掙扎着,這可以幫助任何人嗎?

這是錯誤

您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的正確語法手冊 'ORDER BY photo_id DESC LIMIT 1)UNION(SELECT photo_id FROM userphotos WHERE河粉' 在行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

*「這是一個錯誤,但它在我的網頁無法顯示」 * - 錯誤是如果它是。?你知道的事情出了錯,但沒有「官員ial-looking「消息,那麼這意味着你沒有檢查/捕獲它們。將錯誤報告添加到文件頂部 'error_reporting(E_ALL); ini_set('display_errors',1);'看看它是否產生任何東西。 –

+0

我在頁面中添加了這些內容,但仍然沒有運氣。它只在我刪除WHILE時顯示錯誤。 – Dave

+0

旁註** Q:**你爲什麼要進出PHP;有沒有特別的理由需要你這樣做? –

回答

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的所以它死有

+0

我的頁面已經有數據庫連接,如圖中所示。 – Dave

相關問題