2013-07-19 33 views
3

我想刪除我的MYSQL數據庫中的特定條目。刪除特定的MySQL數據庫條目

數據庫:PhotoID,IDCount,UserID。

這是根據ID刪除照片的代碼。

function delete($IdPhoto) { 

$result = query("DELETE from photos WHERE IdPhoto='%d'", $IdPhoto); 
if (!$result['error']) { 
    // if no error occured, print out the JSON data of the 
    // fetched photo data 
    print json_encode($result); 
} else { 
    //there was an error, print out to the iPhone app 
    errorJson('Photo stream is broken'); 
} 
} 

這與iOS應用程序配對,該應用程序始終抓取當前照片ID。當按下按鈕時,API中的刪除功能將被觸發。這似乎並不奏效。

下面的查詢工作(具體ID):

$result = query("DELETE from photos WHERE IdPhoto=10"); 

任何幫助,將不勝感激。我們的目標是根據我們在iOS應用中獲取的$ IdPhoto刪除照片。

+0

query()函數返回什麼? – andrewsi

+0

沒什麼特別的。實際上一點都沒有。 – qweqweqwe

+0

那你爲什麼要檢查'$ result ['error']'是否存在,如果query()不返回任何東西? – andrewsi

回答

1

試試這個:

$result = query("DELETE from photos WHERE IdPhoto={$IdPhoto}"); 
1

做你試過這樣:

 $result = mysql_query("DELETE from photos WHERE IdPhoto='$IdPhoto' "); 

你應該使用mysql_query

+0

是的。這不行;( – qweqweqwe

+0

檢查我更新的答案 –

1

..IdPhoto='%d' 

應該

..IdPhoto=%d 

由於int值不應該由quotes

0

的「=」將僅比較兩個int值或雙精度值包圍。確保你在比較類型int。因此你的刪除函數應該傳遞一個int值,否則你可能需要像getIntvalue()這樣的函數來提取int值。