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'];
}
}