douying4909 2017-10-03 07:41
浏览 312
已采纳

获取数据库数据时出现非法字符串偏移警告

What is wrong here:

$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'>
"; // line 88
}
echo $items;

Warning:
Illegal string offset 'fname' ... on line 88

  • 写回答

1条回答 默认 最新

  • dsaob80228 2017-10-03 07:46
    关注

    fetchColumn returns the next column directly, not an array that represents the row:

    $fname = $st->fetchColumn();
    $items .= "<img class='imgr imgr2' data-fname = '${fname}' src='../banners/${fname}.jpg' alt='img'>
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制