3

I've seen references to Ajax for this, but I'm not entirely sure how I could integrate that with the arrays and still have a functioning system. I want to change the value of $place and $title each time a user presses the button, and I know that I'll need an if statement and some way of processing a form (no clicks in PHP), but I don't know anything else beyond that. I've pasted my PHP and the HTML button below:

<!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>
1
  • Please post your full HTML. Commented Jan 14, 2015 at 5:35

2 Answers 2

2

maybe this could give you idea on how to do it.

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>

what I did is need to put the button inside a form and put a method= post and make it submit it to the same page

i also store the count in a hidden input and pass it always when the form is submitted and update its value on the form,

try to modify according to your need

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is very useful and can be easily modified :D
1
<?php
    $_SESSION["place"] = 0;
    $place = 0;
    $title = 0;
    session_start();
    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>', "", "");

    if($_POST['clickies'] and $_SERVER['REQUEST_METHOD'] == "POST"){
        $_SESSION["place"] =  $_SESSION["place"] + 1;
        $title = 1;
    }
    echo $links[$_SESSION["place"]];
    $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 method="post" action="">
      <input type="submit" id="clickies" name="clickies" value="submit" />
</form>

you can use session of php.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.