2012-05-01 73 views
0

所以我有這個查詢裏面搜索torrent_download,torrent_download只能是1或者0;if else sql語句後查詢

$sql_istorrenthere = $this->query("SELECT torrent_download 
FROM " . DB_PREFIX . "auctions WHERE 
       auction_id='" . $item_details['auction_id'] . "'"); 
if (empty($sql_istorrenthere)) 
{ 

     $display_output = GMSG_NOTORRENT;} 
     else 
     $display_output = GMSG_TORRENT; 
} 

我想要做的是if (empty($sql_istorrenthere))喜歡的東西if $sql_istorrenthere == 1 then $display_output = GMSG_NOTORRENT; else $display_output = GMSG_TORRENT;

如何做到這一點更換部件?

+0

'的var_dump($ sql_istorrenthere);' –

+0

@KarolyHorvath我得到這個在類型(MySQL的結果)頁面資源(156)的頂部,但在GMSG –

+0

如何連接到你的數據庫沒有變化?你可能需要使用'$ row = $ sqlistorrenthere-> fetch_assoc(); var_dump($ row);'做完'$ this-> query(...);' – Daan

回答

1

您首先必須獲取結果行,但很難分辨出因爲您沒有告訴我們您使用的框架/數據庫抽象層。檢查文檔,你想以數組或對象的形式獲取結果。

對於數組:

嘗試用var_dump顯示的結果,如果你成功了,你會看到用鑰匙將torrent_download鍵的數組。然後簡單地比較$res['torrent_download']1

+0

你的意思是顯示函數查詢? –

+0

好的,我現在明白了,但它顯示了一些在網頁頂部的亂碼,如何刪除它?它顯示這個數組(2){[0] =>字符串(1)「0」[「torrent_download」] =>字符串(1)「0」} –

+0

刪除您爲調試添加的代碼。 –