我尝试在这种情况下绑定一个值数组$ownco
在另一个选择查询中,但它不起作用。如何实现它,在第二个查询中检查/传递所有值?
<?php
$hostname = 'localhost';
$user = 'root';
$password = '';
$username = $_COOKIE['username'];
try {
$dbh = new PDO("mysql:host=$hostname;dbname=searchfood", $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "SELECT id_post
FROM comments
WHERE username = $username
ORDER BY id DESC"; // oder (longitude between $loo and $lo or latitude between $laa and $la) versuchen
if ($res = $dbh->query($sql)) {// need to add this line in your code
// then after fetchColumn
$ownco = $res->fetchAll();
}
} catch (PDOException $e) {
echo $e->getMessage();
}
$userid = $_COOKIE['userid'];
try {
$dbh = new PDO("mysql:host=$hostname;dbname=searchfood", $user, $password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "SELECT id, autorid, autor, date, longitude, latitude, title, text, town, time
FROM posts
WHERE id = $ownco
ORDER BY id DESC"; // oder (longitude between $loo and $lo or latitude between $laa and $la) versuchen
if ($res = $dbh->query($sql)) {// need to add this line in your code
// then after fetchColumn
$resultcom = $res->fetchAll();
}
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
答案 0 :(得分:1)
您的问题存在一些问题。
$ownco
不包含您期望的数据结构。 JOIN
。答案 1 :(得分:0)
更改您的第二个查询,如下所示
$sql = "SELECT id, autorid, autor, date, longitude, latitude, title, text, town, time
FROM posts
WHERE id in (" . implode(",",$ownco) . ")
ORDER BY id DESC";