我查找与口袋妖怪关联的图像并用 php.ini 显示它。然后我希望能够通过单击它来“翻转卡片”。我已经第一次单击向下,但是第二次单击以将卡翻转过来是行不通的。我认为这是我在 JS 中的 php 变量的语法:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>
'Murica!
</title>
<script>
function changeImage()
{
element=document.getElementById('pokemon_card')
if
(element.src.match("http://dmisasi.files.wordpress.com/2010/12/david-pokemon-card- back.jpg?w=750"))
{element.src="'.$result['image_url'].'";} //<- no idea how to express the php string variable here
else
{element.src="http://dmisasi.files.wordpress.com/2010/12/david-pokemon-card-back.jpg? w=750";}
}
</script>
</head>
<body>
<?php
$dbhost = 'databasePlace';
$dbname = 'mine';
$dbuser = 'me';
$dbpass = '******';
$link = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
mysqli_select_db($link,$dbname);
$name = $_GET["fname"];
$query = sprintf("SELECT image_url, Type
FROM Pokemon c
WHERE c.name='%s'",
mysqli_real_escape_string($link,$name));
$result = mysqli_fetch_assoc(mysqli_query($link,$query));
echo '<img id="pokemon_card" onclick="changeImage()" height="225"
width="165" src="'.$result['image_url'].'"/>';
mysqli_close($link);
?>
</body>
</html>