我想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>
答案 0 :(得分:2)
您可以使用MySQL的IN
或BETWEEN
关键字,而不是使用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 . "'/>";
}