[英]How to display random image and text from MySQL Database with PHP
I'm trying to make this html page (display.html) display a random image submission and random text submission from my MySQL table labeled "submissions". 我正在尝试使此html页面(display.html)显示来自我的MySQL表中标有“提交”的随机图像提交和随机文本提交。
This is the current code for display.html: 这是display.html的当前代码:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>MIXED MESSAGES</title>
</head>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("host", "username", "password") or die(mysql_error()) ;
mysql_select_db("voiid") or die(mysql_error()) ;
?>
<body>
<?php
$qry = mysql_query("SELECT * FROM submissions ORDER BY RAND() LIMIT 1");
while($rand = mysql_fetch_assoc($qry)){
echo $rand['name'];
echo $rand['pic'];
}
?>
</body>
</html>
At the moment the page displays the text correctly, but instead of displaying a random image it will display a random images file name IE hello5650_707133731307_3064319_n.jpg. 目前,该页面正确显示了文本,但未显示随机图像,而是显示了随机图像文件名IE hello5650_707133731307_3064319_n.jpg。 I would also like a break between the text and the image.
我也想在文字和图像之间休息一下。
Both the text and photo fields are VARCHAR(200). 文本字段和照片字段均为VARCHAR(200)。 Not sure if I should be using a different data type.
不知道我是否应该使用其他数据类型。
Any help is very appreciated! 任何帮助都非常感谢!
$qry = mysql_query("SELECT * FROM submissions ORDER BY RAND() LIMIT 1");
$ qry = mysql_query(“选择*来自提交的订单,按RAND()限制1”);
while($rand = mysql_fetch_assoc($qry)){ echo $rand['name'] .
while($ rand = mysql_fetch_assoc($ qry)){echo $ rand ['name']。 "
”
"; echo "http://www.site.org/images/".$rand['pic'] ."'>”;回显“ http://www.site.org/images/”.$rand['pic']。”'>
"; }“;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.