in web system have 3 files database.php , functions.php, dashboard.php
this how 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 below
function getquizes($quizno) { if($quizno==null) { $quizno=0; } include_once('database.php'); $sql = "select * quiz limit ".$quizno.",1"; $result = $conn->query($sql); while($row=$result->fetch_assoc()) { echo $row['question'],$quizno; } $quizno++; return $quizno; }
when clicked submit button data go functions.php file , comes dashboard.php again $i becomes null. can assign null first time.if yes,how can that.
store $i
in session , load in every request, if it's not set in $_session
set $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>
Comments
Post a Comment