这个PHP有什么问题?

时间:2012-05-02 21:04:27

标签: php mysql

  

可能重复:
  How to select rows that start with “<img” with an IF statement

当我用img开头的文本时,我试图将“/ images”添加到text_image行的开头。它给了我一个错误。

while($row = mysql_fetch_array( $result3 )) {
    echo "<div class='entry'>";
    $images = (substr($row['text_image']), 0, 3) == 'img') ? "/images" : "";
    echo $images . $row['text_image'];
    echo "</div>";
}

2 个答案:

答案 0 :(得分:5)

你有一个额外的括号。尝试:

$images = (substr($row['text_image'], 0, 3) == 'img') ? "/images" : "";

答案 1 :(得分:0)

while($row = mysql_fetch_array( $result3 )) {
echo "<div class='entry'>";
$images = (
             substr($row['text_image'], 0, 3)

             == 'img') ? "/images" : "";
echo $images . $row['text_image'];
echo "</div>";
}