分享

PHP-如何单击更改数组值?

 印度阿三17 2019-10-28

我已经看到了对此的引用,但是我不完全确定如何将其与数组集成并且仍然具有正常运行的系统.我想每次用户按下按钮时更改$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./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 "></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:///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 "></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
并将其提交到同一页面

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

尝试根据您的需要进行修改

来源:https://www./content-1-531101.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多