我的数据库架构在登录表中有一个device_token
字段。我想在调用此语句时选择它。
$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
关键是上面的语句使用了一个连接,我需要帮助从给定当前语法的登录表中选择device_token
。我的最终目标是回应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
修改2
这是整个陈述
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'];
}
}
答案 0 :(得分:1)
您没有在查询中选择l.device_token
这就是为什么您无法获得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
用于获取数据
$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'];
}