每當我點擊按鈕,頁面被刷新並丟失了變量中的以前的值。當我使用mt_rand
函數時,獲取的行有時會被複制。點擊每個按鈕上的下一行怎麼做?如何從每個按鈕中的數據庫獲取下一行點擊PHP
取出隨機行是沒有必要的,至少我想按順序得到下一行。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//Database initialization
$StudName ="";
$Name="";
$Task="";
$connection=mysqli_connect("localhost","APB","12345678","apb");
$number=1;
if(isset($_POST["button1"]))
{
$number = mt_rand(1,10);
$s="SELECT * FROM student_list WHERE NUM='$number'";
$r= mysqli_query($connection,$s);
$row = mysqli_fetch_array($r);
$StudName = $row["NAME"];
$Name="";
}
if(isset($_POST["Submit5"]))
{
$numb = mt_rand(1,4);
$s="SELECT * FROM computer WHERE rn='$numb'";
$r= mysqli_query($connection,$s);
$row=mysqli_fetch_array($r);
$Task = $row["task"];
$StudName ="";
$Name ="";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form" action="" name="form1" method="POST" >
<h1>MPTC FRESHER'S DAY CELEBRATION - 2017</h1>
<h5>This time the lucky one is ...</h5>
<p>
<input type="hidden" name="process" value="1";>
<input onclick="<?php $number=$number+1;?>" name="button1" type="submit" id="button1" value="GENERATE" />
<br/>
<input id="t1" name="textfield" type="text" value="<?php echo $StudName; ?>" />
</p>
<p>
<h5>Be Ready !! </h5>
<input type="submit" value="TASK" name="Submit5" value="COMPUTER" />
<br/>
<input name="textfield3" type="text" value="<?php echo $Task; ?>" />
</p>
</form>
</body>
</html>
請問您提供的代碼?是緊急狀況 –