简体   繁体   English

会话变量不定期增加

[英]session variable not increment regularly

I am developing a smartphone web app that is a game of question answer using jquerymobile API. 我正在开发一个智能手机Web应用程序,该应用程序使用jquerymobile API进行问答游戏。 when a user click on next button that is a anchor tag then i switch to other page and increment the $_SESSION['questionNo'] value. 当用户单击是锚标记的下一个按钮时,我将切换到其他页面并增加$ _SESSION ['questionNo']值。 The problem is $_SESSION['questionNo'] value increment from 1 to 4 and then again became $_SESSION['questionNo'] is 1. why it's happening i don't know. 问题是$ _SESSION ['questionNo']的值从1递增到4,然后又变成$ _SESSION ['questionNo']为1。为什么我不知道它的发生。 Here is my code 这是我的代码

<?php session_start();
include("connect.php");
include("header1.php");

$attemp=$_SESSION['questionNo'];
echo $attemp;
$sql = sprintf("select * from question order by pk_id ASC limit %s,%s",$attemp,1);
$result = mysql_query($sql) or die(mysql_error());
$result2=mysql_fetch_array($result);
?>

<div data-role="page" id="group">
<div class="main">
<div id="header2" class="clearfix">
<table  border="0" width="100%" id="table">

<tr><td colspan="5"><hr></td></tr>
<tr>
<td colspan="2" id="menu_button1">
    <a href="reset.php" rel="external">Reset</a>
</td>

<td align="center">
    Score : 50%
</td>
<td>&nbsp;</td>
<td id="menu_button2">
    <a href="test.php" rel="external">Next</a>
</td>
</tr>

-------------
test.php page
-------------
<!DOCTYPE html> 
<html> 
<head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="css/style.css" media="handheld, screen" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../css/jquery.mobile-1.0a1.min.css"/>
    <script src="jquery-1.4.3.min.js"></script>
    <script src="jquery.mobile-1.0a2.min.js"></script>
    <script src="jquery-1.8.2.min.js"></script>
</head> 
<body> 

<div data-role="page">

    <div data-role="header">
        <h1>My Title</h1>
    </div>

    <div data-role="content">   
        <?php 
            ++$_SESSION['questionNo'];
            header('Location:startGame.php');
            exit;
        ?>      
    </div><!-- /content -->

</div><!-- /page -->

</body>

can any one tell me why $_SESSION['questionNo'] not incrementing regularly??? 谁能告诉我为什么$ _SESSION ['questionNo']不定期增加???

Use session_start(): 使用session_start():

<?php 
session_start();
++$_SESSION['questionNo'];
header('Location:startGame.php');
exit;
?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM