0
我用第一个查询将任意值保存到数组$ownco
。通过第二个查询,我尝试获取id
与阵列$ownco
中的值相同的所有表格帖子行。用数组值选择查询
两个错误:
SQLSTATE [42S22]:柱未找到:1054未知列在 '阵列' 'where子句'
:Array对字符串的转换在管线34
$hostname='localhost';
$user='root';
$password='';
$useron = $_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 = '$useron'
ORDER BY id DESC"; // oder (longitude between $loo and $lo or latitude between $laa and $la) versuchen
if ($own = $dbh->query($sql)) {// need to add this line in your code
// then after fetchColumn
$ownco = $own->fetchAll();
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
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 in (" . implode(",",$ownco) . ") // line 34
ORDER BY id DESC"; // oder (longitude between $loo and $lo or latitude between $laa and $la) versuchen
if ($resco = $dbh->query($sql)) {// need to add this line in your code
// then after fetchColumn
$resultcom = $resco->fetchAll();
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
你可以分享'的var_dump(破灭( “”,$ ownco))'结果? –
不需要这2个查询,这可以在一个连接中完成 –
您可以做一个子查询:'SELECT id,.... FROM posts WHERE id in(SELECT id_post FROM comments WHERE ....)ORDER BY ID DESC' – Steve