[英]why does my pdo like search not find the second one?
I am doing a search of usernames based on a text input of names like so: 我正在根据名称的文本输入搜索用户名,如下所示:
// find users
$users = explode(',', $_POST['to']);
$user_id_list = array();
print_r($users);
foreach ($users as $user)
{
$db->sqlquery("SELECT `user_id` FROM `users` WHERE `username` LIKE ?", array("%$user%"));
$user_id = $db->fetch();
$user_id_list[] = $user_id['user_id'];
}
print_r($user_id_list);
But it only ever seems to find the first one and not the second? 但是它似乎只找到第一个而不找到第二个了吗? Am i doing something wrong?
难道我做错了什么?
PDOStatement::fetch
returns only the next row of the result data. PDOStatement::fetch
仅返回结果数据的下一行。 You can iterate through $db->fetchAll()
or use while (($row = $db->fetch()) !== false)
to access all the returned rows. 您可以遍历
$db->fetchAll()
或使用while (($row = $db->fetch()) !== false)
访问所有返回的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.