目前,我可以显示数据库中的图像,但是如何使用搜索栏搜索特定图像并显示到网页中,这是最好的方法,有人可以通过此代码帮助我,因为我PHP的基本学习者..
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("display_images");
$res=mysql_query("select *from table1");
echo "<table>";
while($row=mysql_fetch_array($res))
{
echo "<tr>";
echo "<td>";?> <img src="<?php echo $row["images1"];?>" height="100" width="100"> <?php echo "</td>";
echo "<td>"; echo $row["name"]; echo"</td>";
echo "</tr>";
}
echo "</table>";
?>
</table>
</body>
答案 0 :(得分:1)
正如我所说的mysql_*
现在已被弃用并删除了库,我将为您提供mysqli_*
的示例示例
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST">
<input type="text" name="image_name" placeholder="type a name and hit submit button to see particular image">
<input type="submit" name="submit" value="submit">
</form>
<table>
<?php
$connection = mysqli_connect( "localhost", "root", "", "display_images" ) or die( mysqli_connect_error() );
$query = "SELECT * FROM table1";
if( !empty( $_POST['image_name'] ) ){
$image_name = $_POST['image_name'];
$query = "SELECT * FROM table1 WHERE images1 LIKE %$image_name%";
//you can do $image_name% or %$image_name based on your requirement
}
$result = mysqli_query( $connection, $query ) or die( mysqli_error( $connection ) );
while( $row = mysqli_fetch_assoc( $res ) ){
?>
<tr>
<td>
<img src="<?php echo $row["images1"];?>" height="100" width="100">
</td>
<td><?php echo $row["name"];?></td>
</tr>
<?php }?>
</table>
</body>
注意: :使用准备好的语句来防止SQL注入
参考:-
答案 1 :(得分:1)
尝试使用此示例代码
this
或尝试
this.myFormGroup