douwen7603 2012-09-22 16:08
浏览 12
已采纳

保留PHP中连续页面Releaods的信息

Here is the Aim of my Program.

  1. I Want around 5-6 Circles to be shown on the page, of colors red and green.
  2. When, any of the circle is clicked. Its color changes to BLUE.
  3. Then, if i click any other circle on the page its color should also change to BLUE, and the circle previously clicked should also show as BLUE.
  4. So, if i click all circles one by one, in succesive pageloads, all the circles should show up as blue.
  5. And, when a blue circle is clicked, it should show its original color.
  6. This loop should continue for-ever, until the page is closed.

This is what i have done till now.

define("SIZE", 5); //the no. of circles

 class redblock
     {
     var $color;


         function set_color($data)
     {
         $this->color = $data;
     }
     function get_color()
     {
         return $this->color;
     }
     function image_source()
     {
         $rval2 = $this->get_color();
         echo $rval2;
     }
     function display_block()
     {
         $rval = $this->get_color();
         echo "<img src = '",$rval,"' width=120> </br> " ; 
         }
 }

for ($i=0 ; $i < SIZE ; $i++ ) //INIT color blocks

             { $rb[$i] = new redblock ; }



for ($i=0 ; $i < SIZE ; $i++ ) //color set
{
    if(!isset($_POST[$i.'form']))
    {    
        if ($i % 2 == 0) //even blocks are green
            $rb[$i]->set_color("green.jpg");
        else                    //odd blocks are red
            $rb[$i]->set_color("red.jpg"); 
    }
    if ( $_POST[$i.'form'] == "blue.jpg" )
        $rb[$i]->set_color("blue.jpg");

    if(isset($_POST[$i.'form']))
        $rb[$i]->set_color("blue.jpg");
} ?>



<?php

// BOTH BLOCKS when clicked repeatedly should turn to white and fro.

for ($i=0 ; $i < SIZE ; $i++ ) //display the blocks
{
    echo "<form method ='post'>";
    echo "<input type = 'image' width='120' src ='",$rb[$i]->image_source(),"'>";
    echo "<input type='hidden' name='".$i,"form' value='",$rb[$i]-get_color(),"'>";
        echo "</form>";
    }

?>

What Happens, in this code. 1. Suppose, i click Circle 1. It turns to blue. 2. Then i click circle 2, it turns blue, but circle 1 becomes green again. I want circle one to retain the blue color.

Please give me the correct code, or guide me in the right direction. Even, a small help will be largely appreciated.

I have no knowledge of Javascript, etc. I only know PHP and HTML/CSS.

Thank you.

  • 写回答

2条回答 默认 最新

  • donglu1881 2012-09-22 16:17
    关注

    You can use either $_SESSION variables or set a cookie using setcookie() and then retrieving it with $_COOKIE on the successive page loads. Either way will get you temporary storage of the values. Sessions are the way to go if you want the values to disappear after the browser is closed. Cookies will persist until they expire or are cleared by the user.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?