我正在开发一个查询数据库的小型 Web 应用程序。我希望脚本只在每张闪存卡上循环一次,并在最后显示“堆栈结束”警报,但随着脚本的编写,它将无限期地滚动整个集合。我想知道是否有人可以帮助我解决这个问题?该数据库具有 card_id (1,2,3...[每个条目都有一个唯一编号])、card_type (0 [基于术语]、1 [基于问题])、类 (主题)、子类 (划分该主题),side_1(数据),side_2(数据)。这是我到目前为止的代码:
<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="";
$username="";
$password="";
$dbname="";
$usertable="flash_cards";
$question = "side_1";
$answer = "side_2";
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);
$count=0;
// this section generates the flashcards
$query = "SELECT * FROM $usertable ";
if(empty($_GET)) {
}
else {
$query .= " WHERE ";
if($_GET["sub_class"] != null){
$query .= "sub_class = '".$_GET["sub_class"]."'";
if($_GET["card_type"] != null){
$query .= " AND card_type = ".$_GET["card_type"];
}
}
else if($_GET["card_type"] != null){
$query .= " card_type = ".$_GET["card_type"];
}
}
$query .= " ORDER BY RAND() ";
//echo $query;
$result = mysql_query($query);
if($result){
while($row = mysql_fetch_array($result)){
if($count == 0){
$class = $row["class"];
$sub_class = $row["sub_class"];
echo "<input type=\"hidden\" id=\"".$count."\" value=\"".$class." - ".$sub_class."\"/>";
$count += 1;
echo "<input type=\"hidden\" id=\"".$count."\" value=\""."\"/>";
$count += 1;
}
$name = $row["$question"];
$name2 = $row["$answer"];
echo "<input type=\"hidden\" id=\"".$count."\" value=\"".$name."\"/>";
$count += 1;
echo "<input type=\"hidden\" id=\"".$count."\" value=\"".$name2."\"/>";
$count += 1;
}
echo "<input type=\"hidden\" id=\"count\" value=\"".$count."\"/>";
}
?>