gpt4 book ai didi

php - 从特定用户 ID 抓取流

转载 作者:行者123 更新时间:2023-11-29 08:26:08 27 4
gpt4 key购买 nike

我正在创建一个应用程序,用于获取用户通过我的服务上传的照片并将其显示在全局新闻源中。

我在为具有特定用户 ID 的特定用户(而不是所有人)创建 PHP MYSQL 代码时遇到了麻烦。

我的数据库在照片表中有以下内容:IdPhoto、IdUser、标题。

以下是我获取全局提要的方法(有效):

//stream API
//
// there are 2 ways to use the function:
// 1) don't pass any parameters - then the function will fetch all photos from the database
// 2) pass a photo id as a parameter - then the function will fetch the data of the requested photo
//
// Q: what "$IdPhoto=0" means? A: It's the PHP way to say "first param of the function is $IdPhoto,
// if there's no param sent to the function - initialize $IdPhoto with a default value of 0"

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);
}

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

我想做类似的交易。但对于具有特定 ID 的特定用户。关于此所需的 MYSQL 代码/PHP 代码有什么建议吗?

我已为我的个人资料功能尝试了以下方法,但似乎不起作用:

SELECT IdPhoto, IdUser,title, username FROM photos WHERE IdUser=$IdUser;

我还使用案例调用 index.php 文件中的函数:

case "stream":
stream((int)$_POST['IdPhoto']);
break;

知道我的个人资料功能也需要什么吗?

最佳答案

查询应该是:

SELECT IdPhoto, IdUser, title FROM photos WHERE IdUser = $IdUser;

关于php - 从特定用户 ID 抓取流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17863580/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com