HTML
<a href="samcheckdb.php"><img src="getdesserticecreamimage.php?itemId=oepd1007" alt="image" id="img1"></a></li>
samcheckdb.php
<?php
$hostname="localhost";
$username="root";
$password="tiger";
$itemId=intval(\filter_input(\INPUT_GET,'itemId'));
* @var $dbhandle type */
$dbhandle = \mysqli_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
/* @var $select type */
$select= \mysqli_select_db($dbhandle,"sample")
or mysqli_error($dbhandle);
$sql="select subtitle,descript from dessert where itemId='oepd1007'";
$result=mysqli_query($dbhandle,$sql);
$row= mysqli_fetch_array($result);
$subtitle=$row['subtitle'];
$descript=$row['descript'];
mysqli_close($dbhandle);
?>
<html>
<head>
<title>Customer menu card</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" type="text/css" href="dessert.css">
</head>
<body>
<form id='custdisp' name='custdisp' method='post' action="samcheckdb.php" enctype="multipart/form-data">
<div id="d"><?php echo $descript ?></div>
<div id="s"><?php echo $subtitle?></div>
</form>
</body>
</html>
我能够使用此代码从数据库中检索相应的数据。但是我有n个图像,不可能创建那么多页面,我不认为它是最优的。如何我为多个图像做这个???
答案 0 :(得分:1)
你可以点击
<img src="getimage.php?itemId=oepsv1007" alt="image" id="img1" onclick="get_detail('oepsv1007');">
然后执行ajax调用以使用此id获取详细信息。
javascript功能
function get_detail(id) {
// ajax call
}