如何在php

时间:2017-06-22 22:21:16

标签: php mysql

我想echo img每次$i增加echo,但只有$i是最后for($i=0; $i<=5;$i++) $sql="SELECT DISTINCT id, Make FROM sve WHERE id='".$i."'"; $rezult=mysqli_query($db, $sql); $red=mysqli_fetch_object($rezult); echo "<img src='brend/brend$red->id.png' class='imgbrend' strana='".$red->Make."'/>";

make_optional_tuple<int, double, std::string>

1 个答案:

答案 0 :(得分:2)

您可以使用MySQL的INBETWEEN关键字,而不是使用for循环,然后迭代结果集。

您的查询会变成这样:

SELECT DISTINCT id, Make FROM sve WHERE id BETWEEN 0 AND 5

然后你需要一个这样的循环:

while ($red = mysqli_fetch_object($rezult)) {
    echo "<img src='brend/brend" . $red->id . ".png' class='imgbrend' strana='" . $red->Make . "'/>";
}

完整代码:

$sql = "SELECT DISTINCT id, Make FROM sve WHERE id BETWEEN 0 AND 5";

$rezult = mysqli_query($db, $sql);
while ($red = mysqli_fetch_object($rezult)) {
    echo "<img src='brend/brend" . $red->id . ".png' class='imgbrend' strana='" . $red->Make . "'/>";
}