douke3442 2012-06-14 12:07
浏览 44
已采纳

每次用户访问页面时如何显示数字1

I have a problem when it comes to displaying the correct number in my heading. When a user submits a page and navigates to this current page, I want the heading below to appear:

CREATING QUESTIONS AND ANSWERS: SESSION (AAA) 1 OF 3

As you can see it above it starts with the number 1 as the user is creating their first session. The problem I am getting is that it never displays number 1, it just keeps displaying this below:

CREATING QUESTIONS AND ANSWERS: SESSION (AAA) 3 OF 3

It keeps displaying the number 3 which is incorrect as if the user enters the current page for the first time then obviousl they don't start with session 3, they start with session 1, then 2 then 3.

So my question is how do I get "SESSION 1" to be displayed when the useer enters the page for the first time?

Below is the current code I have:

  if(isset($_POST['sessionNum'])){
                //Declare my counter for the first time

                $_SESSION['initial_count'] = $_POST['sessionNum'];
                $_SESSION['sessionNum'] = $_POST['sessionNum'];

        }

    if (!isset($_SESSION['sessionCount'])) {
        $_SESSION['sessionCount'] = 1;
    }
    else if ($_SESSION['sessionCount'] < $_SESSION['sessionNum']) {
        ++$_SESSION['sessionCount'];
    }


    $sessionMinus =  $_SESSION['sessionCount'];

...

    <h1>CREATING QUESTIONS AND ANSWERS: SESSION (<?php echo $_SESSION['id'] ?>) <?php echo $sessionMinus ?> OF <?php echo $_SESSION['initial_count'] ?></h1>
  • 写回答

1条回答 默认 最新

  • douzhanlai4671 2012-06-14 12:24
    关注

    When you are setting for the first time:

    //Declare my counter for the first time
    $_SESSION['initial_count'] = $_POST['sessionNum'];
    

    Set it to 1! Because after that isset will return true, and so, it will not be set to 1...

    //Declare my counter for the first time
    $_SESSION['initial_count'] = 1;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路