How to assign a value only for first time
In my web system I have 3 files those are database.php , functions.php, dashboard.php
This is how my dashboard.php file looks like
<?php
$i=NULL;
if(isset($_POST['next']))
{
$i=getQuizes($i);
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="next" value="Next" type="submit">
</form>
functions.php is like below
function getQuizes($quizNo)
{
if($quizNo==NULL)
{
$quizNo=0;
}
include_once('database.php');
$sql = "SELECT * FROM quiz LIMIT ".$quizNo.",1";
$result = $conn->query($sql);
while($row=$result->fetch_assoc())
{
echo $row['question'],$quizNo;
}
$quizNo++;
return $quizNo;
}
when I clicked the submit button data go to the functions.php file and comes back to the dashboard.php then again $i becomes NULL. can I assign NULL only for first time.if yes,How can I do that.
将$i
存储在会话中,并将其加载到每个请求中,如果未在$_SESSION
设置,则将$i
设置为NULL
<?php
$i = isset($_SESSION['next']) ? $_SESSION['next'] : NULL;
if(isset($_POST['next']))
{
$i = getQuizes($i);
$_SESSION['next'] = $i;
}?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="next" value="Next" type="submit">
</form>
链接地址: http://www.djcxy.com/p/31622.html
上一篇: 为什么Spark中的示例代码不会加载到spark中
下一篇: 如何仅为第一次分配值