如何选择以“< img"开头的行带有IF语句 [英] How to select rows that start with "<img" with an IF statement
问题描述
我在表中有两列Entry
和text_image
.循环查看数组中的所有行时,我可以获得结果,但是我希望它向具有以img
开头的文本的行添加/images
.这是为了将具有"img"(意味着该行中的文本)的行定向到正确的文件夹.它可能需要进一步的解释来说明原因,但我不会介入.
I have two columns, Entry
and text_image
, in a table. When looping to see all the rows in an array, I can get the results, but I want it to add /images
to the rows that have text starting with img
. This is to direct the rows that have "img" (meaning the text within the row) to the correct folder. It might need further explanation to illustrate why but I wont get into it.
while($row = mysql_fetch_array( $result3 )) {
echo "<div class=\'entry\'>";
(I want to add an echo "/images" before the rows that start with "img")
echo $row[\'text_image\'];
echo "</div>";
}
提前谢谢
推荐答案
$images = (substr($row['text_image'], 0, 3) == 'img') ? "/images" : "";
echo $images . $row['text_image'];
这将检查$row['text_image']
的前3个字母是否为img
,然后将$images
设置为/images
,否则将其留空.它将在循环中的每次更新.
This will check if the first 3 letters of $row['text_image']
are img
then set $images
to /images
else it will leave it empty. This will update each time within the loop.
这篇关于如何选择以“< img"开头的行带有IF语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!