警告:非法字符串偏移 - PHP mySQL

时间:2014-08-25 14:31:21

标签: php mysql warnings

警告:非法字符串偏移' slimg'在第82行的/opt/lampp/htdocs/linom/index.php

<?php
    $slider = "SELECT * FROM post ORDER BY id ASC LIMIT 4";
    $slider1 = mysqli_query($connect,$slider);
    $sliderV = mysqli_fetch_array($slider1);

    do {
        printf ("<div class='slider'>
        <a href='view.php?id=%s'>
            <figure>
                <img class='slideimg' src=%s>
                <figcaption>
                    %s
                </figcaption>
            </figure>
        </a>
        </div>",$sliderV['id'],$slider['slimg'],$sliderV['title']); //here is error
    }
    while ($sliderV = mysqli_fetch_array($slider1));
?>

1 个答案:

答案 0 :(得分:2)

您的变量名称不是很清楚。您不小心引用了查询字符串而不是数组:

$sliderV['slimg']

我建议使用更好的变量名称,例如$slider_sql$slider_query$slider