Jump to content

problem with multiple page loads


tennis_mnky

Recommended Posts

I made a program that asks for a grid size, makes a grid, and then displays it.  On the first load it asks for information about size.  On the second page it randomly makes a grid and displays it.  On each page after its suppose to display the grid.  However it is only printing the grid on the second page and not the ones after it.  Here is the code

 

<html>

<body>

<?php

 

$count = $_REQUEST["count"];

 

 

$height = $_REQUEST["height"];

  $width = $_REQUEST["width"];

  $size = $_REQUEST["size"];

  $born = array(1 => 3);

  $live = array( 1 => 2, 2=> 3);

  $grid = $_REQUEST["grid"];

  $grid = unserialize ($grid);

 

If ($count == 0) {

    ask($count);

} elseif($count == 1) {

 

    $grid=makegrid($height,$width);

    $checker = table($grid,$height,$width,$size);

    print "$checker";

    send ($grid,$count);

} elseif ($count >= 2) {

 

    //$grid = livedie($grid,$born,$live,$height,$width);

    $checker = table($grid,$height,$width,$size);

    print "$checker";

    send ($grid,$count);

 

 

 

 

}

 

 

print '<pre>' . print_r($grid, 1) . '</pre>';

function ask($c) {

$c++;

print <<<HERE

    <form method = "post">

    <h1>Choose the size of the grid</h1>

    What height do you want:

 

    <input type = "text" name = "height">

 

    <br>\n<br>\n

 

    What width do you want:

 

    <input type = "text" name = "width">

 

    <br>\n<br>\n

 

    What size do you want? (1 is smallest):

 

    <input type = "text" name = "size">

 

    <br>\n<br>\n

 

 

      <input type = "hidden"

              name = "count"

              value = "$c">

 

    <br>\n<br>\n

 

    <input type = "submit">

 

    </form>

 

 

HERE;

}

 

 

 

//now define functions

  function makegrid($height,$width){

 

  for($i =0; $i < $width; $i++) {

    for($n = 0; $n < $height; $n++) {

    $if = rand(0,1);

    //if is yes or no

    $grid[$n][$i] = $if;}}

    return $grid;

    }

  //end loop, end loop, end funcition

  //array is made with values of 0 or 1

 

 

  function table($grid,$tableHeight, $tableWidth, $cellSize)

  {

 

      //Height and width of the cells

 

      $cellStyle = "height:{$cellSize};width:{$cellSize};";

      $tableHTML = "<table border=\"0\" style=\"font-size:1pt;\">\n";

      for ($row=0; $row<$tableHeight; $row++)

      {

          $tableHTML .= "<tr>\n";

          for ($col=0; $col<$tableWidth; $col++)

          {

              $cellColor= ($grid[$row][$col]==1) ? "000000" : "F";

              $tableHTML .= "  <td width=\"0\" style=\"{$cellStyle}background-color:{$cellColor};\"> </td>\n";

          }

          $tableHTML .= "</tr>\n";

      }

      $tableHTML .= "</table>\n";

      return $tableHTML;

 

 

  }

 

 

function send($grid,$count) {

  $count++;

$grid = serialize ($grid);

  print <<<HERE

 

    <form method = "post">

 

    <input type = "hidden"

            name = "grid"

            value = "$grid">

 

    <input type = "hidden"

        name = "count"

            value = "$count">

 

    <input type = "submit">

 

    </form>

 

HERE;

}

 

 

 

 

?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/198579-problem-with-multiple-page-loads/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.