dongzhuandian3292 2016-03-03 06:04
浏览 19
已采纳

如何在此声明中获取设备令牌?

My database schema has a device_token field in the login table. I want to select it when this statement is called.

    $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);
    //Use the result of one php function in another php file

The thing is the statement above uses a join and I'll need help selecting the device_token from the login table given the current syntax. My ultimate goal is to echo the device_token so I want to:

  • Select it in the statement above
  • Store it in a variable
  • Echo it out

How can one do this?

Updated code

SELECT p.IdPhoto, p.title, l.IdUser, p.username, l.device_token FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto='%d' LIMIT 1", $IdPhoto

Edit 2

Here is the whole statement

function stream($IdPhoto=0) {

if ($IdPhoto==0) {

    // load the last 50 photos from the "photos" table, also join the "login" so that you can fetch the 
    // usernames of the photos' authors
    $result = query("SELECT IdPhoto, title, l.IdUser, username FROM photos p JOIN login l ON (l.IdUser = p.IdUser) ORDER BY IdPhoto DESC LIMIT 50");

} 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);
    //Use the result of one php function in another php file
    //Either result or idphoto since idphoto can successfully get the photo we want etc
    //if i store id photo can i query idphoto based on idphoto like above?
    //get device token here?

    $result = mysql_query("SELECT p.IdPhoto, p.title, l.IdUser, p.username, l.device_token FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto=%d LIMIT 1", $IdPhoto);

while ($row=  mysql_fetch_assoc($result)){
  echo $row['device_token'];
}
}
  • 写回答

1条回答 默认 最新

  • doulupian8725 2016-03-03 06:05
    关注

    You are not selecting l.device_token in your query that's why you are not able to get the value of device_token.

    SELECT p.IdPhoto, p.title, l.IdUser, p.username, l.device_token FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto=%d LIMIT 1", $IdPhoto
    

    For fetching the data

    $result = mysql_query("SELECT p.IdPhoto, p.title, l.IdUser, p.username, l.device_token FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto=%d LIMIT 1", $IdPhoto);
    
    while ($row=  mysql_fetch_assoc($result)){
          echo $row['device_token'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探