由于缺少更好的术语,我有一个“链接”到 onClick 事件的 switch 语句。当开关中有一个案例时,它可以工作。当所有四个案例都处于活动状态时,它们都不起作用。感谢您的任何帮助/建议,非常感谢。
下面的代码:
PHP 文件(mapcontroller.php):
function playerMove($direction)
{
Global $mysqli;
$sqlMoveNorth = "UPDATE ss_character SET coord_y = coord_y + 1 WHERE username = '".$_SESSION['usr']."'";
$sqlMoveSouth = "UPDATE ss_character SET coord_y = coord_y - 1 WHERE username = '".$_SESSION['usr']."'";
$sqlMoveEast = "UPDATE ss_character SET coord_x = coord_X + 1 WHERE username = '".$_SESSION['usr']."'";
$sqlMoveWest = "UPDATE ss_character SET coord_x = coord_X - 1 WHERE username = '".$_SESSION['usr']."'";
switch ($direction)
{
case "north":
mysqli_query($mysqli, $sqlMoveNorth);
break;
case "south":
mysqli_query($mysqli, $sqlMoveSouth);
break;
case "east":
mysqli_query($mysqli, $sqlMoveEast);
break;
case "west":
mysqli_query($mysqli, $sqlMoveWest);
break;
default:
echo "Pick something!";
break;
}
}
HTML 文件 (travel.inc.php):
<div class="map-wrapper">
<?php $currentPage = $_SERVER['REQUEST_URI']; ?>
<div class="map-move-container">
<div class="map-move-north"><a onclick="<?php playerMove(north); ?>" href="<?php $currentPage ?>"> Move North</a></div>
<div class="map-move-west"><a onclick="<?php playerMove(west); ?>" href="<?php $currentPage ?>"> Move West</a></div>
<div class="map-move-east"><a onclick="<?php playerMove(east); ?>" href="<?php $currentPage ?>"> Move East</a></div>
<div class="map-move-south"><a onclick="<?php playerMove(south); ?>" href="<?php $currentPage ?>"> Move South</a></div>
</div>
</div>