我使用當前的代碼來顯示圖像,取決於從下拉框中選擇的內容,但我正在使用go按鈕。我想從下拉框中選擇圖片來顯示圖片。任何幫助將不勝感激使用下拉框在同一頁上顯示圖像
<form name="product" method="post" action="">
<table align="right" width="10%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Category</td>
<td>
<select name="idnum">
<?php
$sql = "SELECT ID,idnum,title,brief FROM table where passw='tsmith';";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<option value="<?= $row['idnum']; ?>"><?= $row['title']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input name="go" type="submit" value="Go" /></td>
</tr>
</table>
</form>
<div align="center">
<ul class='display'>
<?php
$idnum = (int)$_POST['idnum'];
$sql_search = "SELECT * FROM table WHERE idnum = $idnum";
$search = mysql_query($sql_search);
if (isset($_POST['go'])) {
while ($row = mysql_fetch_assoc($search)) {
$imagepath1= "p".$idnum."n1.jpg";
$path='/components/com/photos/'.$imagepath1;
$image1 =("<img src='$path' width='200' height = '221'/>");
echo $image1;
?>
<img src = "/components/com/photos/p.$row['idnum'].n.jpg">;
<li><a href="<?= $row['title']; ?>"><img src="<?= $row['title']; ?>" border="0"></a></li>
<?php
}
}
else {
}
?>
</div>
你需要一個純JavaScript的解決方案即可。谷歌爲選擇框上的'更改'處理程序,你應該沒問題。 – Jan
'Table'是保留在mysql中的關鍵字它必須在bachtick http://dev.mysql.com/doc/refman/5.7/en/keywords.html – Saty