Php 列出作者和所属头衔

Php 列出作者和所属头衔,php,mysql,Php,Mysql,我需要选择作者(不同的),并为每个作者列出所属的标题,不超过六个月 $items = ''; $sqla = "select distinct auth from posts order by date"; $sta = $db->prepare($sqla); $sta -> execute(); while ($rowa = $sta->fetch()) { $items .= "<div class='auth'>" . mb_strtoupper($

我需要选择作者(不同的),并为每个作者列出所属的标题,不超过六个月

$items = '';
$sqla = "select distinct auth from posts order by date";
$sta = $db->prepare($sqla);
$sta -> execute();
while ($rowa = $sta->fetch()) {
    $items .= "<div class='auth'>" . mb_strtoupper($row['auth']) . "</div>\n";
    $sqlb = "select id, date, title, subtitle, tags, from posts where `auth` = '" . $rowa['auth'] . "' and `date` < date(now() - interval 6 month)";
    $stb = $db->prepare($sqlb);
    $stb -> execute(); // line 29
    while ($rowb = $stb->fetch()) {
        $items .= $rowb['title'] . '\n'; 
    }
}

echo $items;
$items='';
$sqla=“按日期从发布顺序中选择不同的身份验证”;
$sta=$db->prepare($sqla);
$sta->execute();
而($rowa=$sta->fetch()){
$items.=''.mb\u strotupper($row['auth'])。“\n”;
$sqlb=“从'auth`='“$rowa['auth']”和'date`prepare($sqlb);
$stb->execute();//第29行
而($rowb=$stb->fetch()){
$items.=$rowb['title'].\n';
}
}
echo$项目;

第29行出现致命错误。

您可以使用单个查询执行此操作

     select distinct auth,id, date, title, subtitle, tags 
     from posts 
     where  `date` < date(now() - interval 6 month)
     order by date
选择不同的身份、id、日期、标题、副标题、标签
发帖
其中`date`
无论如何,您在第二个查询(标记,)中有一个错误,请先从中删除逗号

 $sqlb = "select id, date, title, subtitle, tags from posts where `auth` = '" . $rowa['auth'] . "' and `date` < date(now() - interval 6 month)";
$sqlb=“从“auth`=”的帖子中选择id、日期、标题、副标题和标签。”$rowa['auth']。“'和'date`
对于作者,您应该参考$rowa

$items .= "<div class='auth'>" . mb_strtoupper($rowa['auth']) . "</div>\n";
$items.=''。mb_strtoupper($rowa['auth'])。“\n”;

此代码看起来不像有29个lines@Adam,我标记了它,错误是什么?可能
选择group_concat(title)作为标题,从发布日期进行身份验证也值得注意的是
$rowa['auth']
将您打开到二阶SQL注入,应该参数化查询。对于asnwer的第二部分,您应该解决错误。我删除了命令,只获取标题,没有作者。您只回显标题。。你也应该添加作者。。但是这意味着你的错误已经解决了。不,我需要一个作者和下面的标题,然后是第二个作者和下面的标题。对于外部的作者,你应该参考$rowa,对于内部的作者,你也应该选择auth列。。