这是我的php和mysql反向代码
<?php
include_once("config.php");
$image_id = $_GET['image_id'];
$res = mysqli_query($mysqli,"SELECT * FROM image WHERE image_id = $image_id");
while($row = mysqli_fetch_assoc($res))
{
$image=$row['path_txt'];
//echo $image;
$path ="<img src='http://localhost:8080/memes/".$image."' />";
echo $path;
}
?>
这是我的HTML代码:
<html> <head> </head> <body> <img src=urlencode("sample.php?image_id=58")/> <img src="<?php include("sample.php?image_id=58");?>"/> <?php echo "<img src= 'localhost:8080/memes/sample.php?image_id=58'/>";; echo "<a href =urlencode("/sample.php?image_id=58")>"; ?> </body> </html>
答案 0 :(得分:0)
最好是为get image source创建一个函数然后再使用。如下所示。
的functions.php
<?php
function getImgSrc ($image_id) {
$res = mysqli_query($mysqli,"SELECT * FROM image WHERE image_id = $image_id LIMIT 0, 1");
$row = mysqli_fetch_assoc($res);
$image=$row['path_txt'];
//echo $image;
$path ="<img src='http://localhost:8080/memes/".$image."' />";
return $path;
}
在index.php中,您需要显示该图像。
<?php
// include functions.php
include 'functions.php';
?>
<img src="<?php echo getImgSrc(58); ?>"/>