2012-05-01 72 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

删除您为调试添加的代码。 –