gpt4 book ai didi

php - 如何通过单击更改数组值?

转载 作者:可可西里 更新时间:2023-11-01 01:00:43 24 4
gpt4 key购买 nike

为此,我看到了对 Ajax 的引用,但我不完全确定如何将其与数组集成并仍然拥有一个正常运行的系统。我想在每次用户按下按钮时更改 $place 和 $title 的值,我知道我需要一个 if 语句和某种处理表单的方法(在 PHP 中没有点击),但我不需要知道除此之外的任何事情。我在下面粘贴了我的 PHP 和 HTML 按钮:

<!DOCTYPE html>
<html>
<head>
<title>StatsCalc V1</title>
<link rel="stylesheet" type="text/css" href="sheen.css">
<link rel="script" type="text/javascript" href="slide.js">
<link rel="icon" type="image/png" href="favicon.ico">
<link href='http://fonts.googleapis.com/css?family=Raleway:500' rel='stylesheet' type='text/css'>
</head>
<body>
<?php
$place = 0;
$title = 0;

echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';

$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");
echo $links[$place];

/*if($_GET){
if(isset($_GET['clickies'])){
$place = 1;
$title = 1;
}
}*/

if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
$place = 1;
$title = 1;
}

$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');
echo $subtitle[$title];

?>
<input type="submit" id="clickies" name="clickies" value="" />
<script src="move.js"></script>
<script src="slide.js"></script>
<script src="jquery-1.11.2.js"></script>
<!--The calculator must be able to field standardised score, standard deviation, and averages (mean/median/mode)-->
<!--Headings will be assigned with an array; slides will be navigated with tabs on either side of the window-->
<!--Credit to https://openclipart.org/detail/171055/normal-distn-shaded-outside-1s-by-oderwald-171055 for the Standardised Score image/label thingy-->
</body>
</html>

最佳答案

也许这可以让您了解如何去做。

if($_SERVER['REQUEST_METHOD'] == "POST") {

if (isset($_POST['clickies'])) {
$count = intval($_POST['count']);
$count++;
$place = $count;
$title = $count;
}

} else {
$place = 0;
$title = 0;
}

echo '<div class="boxes"><h1>Statistics Calculator: Version 1</h1></div>';

$links = array('<div class="fancyBoxes"><a href="standardisedForm.php"><img class="mainPic" src="normalDist.svg" alt="a normal distribution, courtesy openclipart.org"></a></div>', "", "");

echo $links[$place];

echo $place; echo "<br/>";

$subtitle = array('<div class="boxes"><h1>Standardised Score</h1></div>', '<div class="boxes"><h1>Standard Deviation</h1></div>', '<div class="boxes"><h1>Averages</h1></div>');

echo $subtitle[$title];

?>
<form action="" method="POST">
<input type="submit" id="clickies" name="clickies" value="" />
<input type="hidden" id="count" name="count" value="<?php echo $place;?>" />
</form>

我所做的是需要将按钮放在一个表单中并放置一个 method= post并让它提交到同一页面

我还将计数存储在隐藏的输入中,并在提交表单时始终传递它并更新其在表单上的值,

尽量根据自己的需要修改

关于php - 如何通过单击更改数组值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com