[英]Php : How can I make values that have been saved in a table appear on the page as being checked?
[英]Using PHP how can i display images which have been saved in SQL as a image path
我正在尝试从SQL数据库中检索使用映像路径保存的映像。 图像保存在服务器上。 当我检索图像时,什么也不会返回。
if(isset($_GET))
{
include_once "mysql_connect.php";
$text = $_GET['text'];
if($text=="")
{
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '1'")
or die(mysql_error());
while( $rows=mysql_fetch_array($query) )
{
$search[] = $rows[0];
}
$result = array();
$result["result"] = 500;
$result["message"] = "Database Read Successfully";
$result["rows"] = $search;
echo json_encode($result);
exit;
代码示例用于用户无需输入值的搜索。 在SQL语句“ URL”内是存储图像路径的字段。图像路径值是完整的URL http://example.com/images/test.jpg并存储为VARCHAR(200)。 任何意见,将不胜感激
您的代码不能正常工作。 您没有关闭if
语句。
另外,当$text
不为空时,您将对数据库没有任何查询...
您将需要以下内容:
if($text==""){
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '1'")
or die(mysql_error());
}
//when $text is not empty...
else{
$query = mysql_query("SELECT `URL` FROM `gallery` WHERE `img_text` LIKE '".$text."'")
or die(mysql_error());
}
while( $rows=mysql_fetch_array($query)){
$search[] = $rows[0];
}
顺便说一下,尝试使用PDO代替mysql_query
,这最后一个已过时,并且容易受到SQL注入的攻击。
图像在服务器中,因此路径仅在服务器上起作用。
如果您执行以下操作:
echo json_encode($result);
我想您正在将此信息返回给客户端,如果要显示它们,图像路径在那里没有任何值!
如果要向用户显示图像,则需要使用HTML img
标签,并用路径FROM THE SERVER填充src属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.