这里有什么问题:
$items = '';
$st = $db->query("select code from map where pos = 'home01' limit 1");
$res = $st->fetchColumn(); // result: 1-2-3-4
$arr = explode("-", $res);
foreach($arr as $el) {
$st = $db->query("select fname from banners where fname = " . $el . " limit 1");
$row = $st->fetchColumn();
$items .= "<img class='imgr imgr2' data-fname = '" . $row['fname'] . "' src='../banners/" . $row['fname'] . ".jpg' alt='img'>\n"; // line 88
}
echo $items;
警告:
Illegal string offset 'fname' ... on line 88
答案 0 :(得分:3)
fetchColumn
直接返回下一列,而不是表示该行的数组:
$fname = $st->fetchColumn();
$items .= "<img class='imgr imgr2' data-fname = '${fname}' src='../banners/${fname}.jpg' alt='img'>\n";