PHP SELECT参数语法

时间:2016-03-10 15:10:08

标签: php mysql sql

我想在下面的陈述中SELECT device_token一个名为 $result = query("SELECT IdPhoto, title, IdUser FROM photos p ORDER BY IdPhoto DESC LIMIT 50") ; 的字段。我的主要目标是选择令牌并将其存储在新变量中。

function stream($IdPhoto=0, $token) {

if ($IdPhoto==0) {

    //Here's where I want to grab the device_token
    $result = query("SELECT device_token, IdPhoto, device_token, title, IdUser FROM photos p ORDER BY IdPhoto DESC LIMIT 50", $token) ;

} else {
    //do the same as above, but just for the photo with the given id
    $result = query("SELECT IdPhoto, title, l.IdUser, username FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d' LIMIT 1", $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');
}
}

以下是该功能的主体以及我尝试过的内容:

($IdPhoto==0)

$token参数是否妨碍device_token变量?如果是这样,怎么能正确地做这些事情呢?

  1. 选择$token

  2. 将其存储在名为$token

  3. 的新变量中
  4. InteractionManager.runAfterInteractions(() => { this.listView.scrollTo({y:0, animated: false}); }); 参数添加到函数名称

1 个答案:

答案 0 :(得分:2)

使用这种方式:

$result = query("SELECT photos.device_token, IdPhoto, title, l.IdUser, username FROM photos p JOIN login l ON (l.IdUser = p.IdUser) ORDER BY IdPhoto DESC LIMIT 50");

两个表中可能都有device_token,结果是从另一个表中得到空device_token