Php 选择缺少的内容

Php 选择缺少的内容,php,sql,select,Php,Sql,Select,你好,我需要这样做 检查一列值,如果该值为一,则$display\u输出为“某物” 如果vaule为2,则$display_输出为“其他” 到目前为止,我有这个 $sql_istorrenthere = $this->query("SELECT CASE WHEN torrent_download ='1' THEN $display_output = GMSG_NOTORRENT ELSE $display_output = GMSG_TORRENT ; FROM" . DB_PREFI

你好,我需要这样做

检查一列值,如果该值为一,则$display\u输出为“某物” 如果vaule为2,则$display_输出为“其他”

到目前为止,我有这个

$sql_istorrenthere = $this->query("SELECT CASE WHEN torrent_download ='1' THEN $display_output = GMSG_NOTORRENT ELSE $display_output = GMSG_TORRENT ; FROM" . DB_PREFIX . "auctions"

你不能那样设置变量。您可以将torrent_download的值设置为'something'或'other'

$sql_istorrenthere = $this->query(
    "SELECT 
      CASE WHEN torrent_download = '1' 
        THEN 'something' 
        ELSE 'other' 
      END AS torrent_download
    FROM" . DB_PREFIX . "auctions"
);
然后在PHP中,您可以执行以下操作:

$response = $sql_istorrenthere -> fetch_assoc();
$display_output = $response['display_output'];

但是有更好的方法可以做到这一点,其中没有一种涉及到试图将变量名设置到查询本身。

那么我该如何设置$display\u输出?@坦白说,不是从SQL。我需要做的是检查torrent download是否是一个值或另一个值,然后让$display\u输出为某个值或另一个值,更改torrent\u download将不会effect@FrankLy不能从SQL查询内部影响变量。SQL查询是由数据库执行的,它们甚至不知道变量的存在。执行查询,分析响应,并相应地设置变量。我该如何分析响应?我猜这是个问题?在我查询torrent\u下载后,如果使用此选项,我需要对$display\u outputh做什么来设置$display\u outputh?我不会在查询中进行设置,但假设您想要
某个东西
其他
,我会进行更新。抱歉,一定是混淆了,我希望$display_output为GMSG_NOTORRENT或GMSG_torrent我在非对象atm上调用成员函数fetch_assoc()时出错,仍在测试中
$response = $sql_istorrenthere -> fetch_assoc();
$display_output = $response['display_output'];