使用PHP显示数据库中的随机图像 [英] Display random image from database using PHP
本文介绍了使用PHP显示数据库中的随机图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望显示随机选择的图像或我从数据库中选择的图像。
但我真的不知道如何正确编码。
我尝试了什么: < br $>
$ query1 = mysqli_query($ db_con, select * from image_tb);
while($ row = mysqli_fetch_array($ query1)){
$ img = ;
$ image_number = $ row [' id 跨度>];
< div class = 阻止内容崩溃 >
< div class = row-fluid padd-bottom >
< span class =code-keyword>< div class = span3 >
//我想在这里显示我的数据库上的第一个图像,但我不知道如何编码它prope RLY。
< a < span class =code-attribute> href = # class = thumbnail >
if(1 == $ image_number){
<? php echo $ img 跨度>; ?>
}
< / a >
< / div >
< div class = span3 >
//数据库中的第二张图片
< a href = # class = thumbnail >
if(2 == $ image_number){
<? php echo $ IMG跨度>; ?>
}
< / a > < / div > < a href = # class = 缩略图 >
< / a > < div class = span3 > < a href = # class = 缩略图 >
//第3张图片
< / a > < a href = # class = thumbnail > ;
if(1 == $ image_number){
<? php echo $ img; ?>
}
< / a >
< / div >
< div class = span3 >
//第4张图片
< a href = # class = 缩略图 >
if(1 == $ image_number){
< ; php echo $ img 跨度>; ?>
}
< / a >
< / div >
< / div >
<? php
}
?>
< / div >
解决方案
< blockquote> query1 = mysqli_query(
db_con, select * from image_tb< /跨度>);
while(
row = mysqli_fetch_array(
i want to display image with randomly selected or the one that i choose from database.
but i don't really know how to code it properly.
What I have tried:
$query1=mysqli_query($db_con,"select * from image_tb");
while($row=mysqli_fetch_array($query1)){
$img = "";
$image_number = $row['id'];
<div class="block-content collapse in">
<div class="row-fluid padd-bottom">
<div class="span3">
//i want to display here the first image on my database but i don't how to code it properly.
<a href="#" class="thumbnail">
if (1 == $image_number){
<?php echo "$img"; ?>
}
</a>
</div>
<div class="span3">
//the 2nd image from database
<a href="#" class="thumbnail">
if (2 == $image_number){
<?php echo "$img"; ?>
}
</a></div><a href="#" class="thumbnail">
</a><div class="span3"><a href="#" class="thumbnail">
//3nd image
</a><a href="#" class="thumbnail">
if (1 == $image_number){
<?php echo "$img"; ?>
}
</a>
</div>
<div class="span3">
//4th image
<a href="#" class="thumbnail">
if (1 == $image_number){
<?php echo "$img"; ?>
}
</a>
</div>
</div>
<?php
}
?>
</div>
解决方案
query1=mysqli_query(
db_con,"select * from image_tb"); while(
row=mysqli_fetch_array(
这篇关于使用PHP显示数据库中的随机图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文