我想創建一個圖片發送一個特定的值綁定到該圖像時點擊一個PHP文件,將作出一個MySQL查詢。有一個圖像發送信息時,單擊變量爲mySQL查詢
例如,假設我有一個動物圖片的HTML頁面,當點擊一個特定的動物圖像時,比如說一張Cat的圖像,它會發送一個值作爲一個值,然後將其分配給一個變量一個MySQL查詢,將從包含貓,狗,馬等動物數據庫中提取不同品種的貓。
//animals.html
<form action="animalQuery.php" method="get"> <input type="image" src="Cat.jpg" name="cats" width="350" height="225">
<form action="animalQuery.php" method="get"> <input type="image" src="Dog.jpg" name="dogs" width="350" height="225">
當Cat.jpg圖像被點擊我要發送的值「貓」來分配:
所以在HTML頁面,animals.html,我使用此代碼創建圖像至$動物變量,以便它基本上使得低於$語句等同於「從動物中選擇*其中品種=‘貓’;」這是一個工作查詢
//animalQuery.php
$animal=$_GET["cats"];
$stmt="select * from Animals where breeds = $animal;";
它的工作原理,如果我硬編碼的$語句用「貓」或「狗」代替變量$ animal,所以我知道查詢是有效的我只是無法弄清楚如何點擊圖像時發送特定的值我想要的變量$動物。一旦我明白了這一點,我應該能夠弄清楚如何讓單個變量$ animal被設置爲某個值,當點擊多個圖像中的一個時,以便一個變量適用於所有圖像。
謝謝。這正是我正在尋找的。簡單直接。我之前使用過鏈接,但並不認爲我可以從中獲取信息,因此我轉而嘗試使用表單。我確信這就是爲什麼當我絕對認爲應該有這個問題時,我很難找到一個簡單的解決方案!選擇這個是因爲它是第一個並立即執行的,但是每個人的帖子都向我介紹了一些新的東西來研究和澄清要點。謝謝你們! – NotIllogical