Php 使用不同的数据库表ID重复div width
我试图用数据库表中的行数将同一个div重复多次。下面是我用我想要的东西做的一个不起作用的例子Php 使用不同的数据库表ID重复div width,php,jquery,html,mysql,Php,Jquery,Html,Mysql,我试图用数据库表中的行数将同一个div重复多次。下面是我用我想要的东西做的一个不起作用的例子 <?php for ($i=0; $i < 3; $i++) { ?><!-- switch the three with the number of rows in the table--> 我希望循环容器并使用值I切换数据库查询 <div id = "bodyContainer"> &
<?php for ($i=0; $i < 3; $i++) {
?><!-- switch the three with the number of rows in the table-->
我希望循环容器并使用值I切换数据库查询
<div id = "bodyContainer">
<form class="review">
<div class="reviewContainer">
<div class = "images">
<?php
$link = mysqli_connect("localhost", "root", "root","DJP");
if (mysqli_connect_error()) {
die("Could not connect to database");
}
$query = "SELECT * FROM reviews WHERE id = '<?php echo $i ?><!--switch the value of i here-->'";
$result=mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
echo '<img height = 90% width = 100% src="data:image/jpeg;base64,'.$row[3].' " />';
?>
</div>
<!--<div class="title">
<?php
//echo $row[1];
?>
</div>-->
<div class = "comment">
<?php
echo $row[2];
?>
</div>
<div class = "rating" style = "float: right;">
<?php
echo $row[4];
?>
<br/>
<br/>
stars
</div>
</div><!--end review-->
</form>
</div><!--end body container-->
<?php;}?><!-- end the for loop so all the divs can be re-done with a new entry for the query. I would move the $link out of loop also.-->
星星
只需获取所有行一次,然后在打印数据时检查它们:
$link = mysqli_connect("localhost", "root", "root","DJP");
if (mysqli_connect_error()) {
die("Could not connect to database");
}
$query = "SELECT * FROM reviews";
$result=mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){ ?>
<div id = "bodyContainer">
<form class="review">
<div class="reviewContainer">
<div class = "images">
<?php
echo '<img height = 90% width = 100% src="data:image/jpeg;base64,'.$row[3].' " />';
?>
</div>
<!--<div class="title">
<?php
//echo $row[1];
?>
</div>-->
<div class = "comment">
<?php
echo $row[2];
?>
</div>
<div class = "rating" style = "float: right;">
<?php
echo $row[4];
?>
<br/>
<br/>
stars
</div>
</div><!--end review-->
</form>
</div><!--end body container-->
<?php } ?>
$link=mysqli_connect(“localhost”、“root”、“root”、“DJP”);
if(mysqli\u connect\u error()){
die(“无法连接到数据库”);
}
$query=“从评论中选择*”;
$result=mysqli\u查询($link,$query);
而($row=mysqli\u fetch\u数组($result)){?>
星星
这非常有效,我只是不确定php循环部分是否有效,因为当我将其放入时,出现了一个错误,但每天都会学到一些新的东西。非常感谢。