我将创建下表
$sql[] = "CREATE TABLE IF NOT EXISTS #__GmQuestions(
QnID int(11) NOT NULL AUTO_INCREMENT,
Question text COLLATE utf8_unicode_ci NOT NULL,
Answer text COLLATE utf8_unicode_ci NOT NULL,
QnLevel int(11) NOT NULL,
QnPrize text COLLATE utf8_unicode_ci,
QnPoints DECIMAL( 10, 2 ) NOT NULL,
PRIMARY KEY (QnID),
)";
和下表
$sql[] = "CREATE TABLE IF NOT EXISTS #__GmHistory(
HsID int(11) NOT NULL AUTO_INCREMENT,
HsGamerID int(11) NOT NULL,
HsQnID int(11) NOT NULL,
Hspoints DECIMAL( 10, 2 ) NOT NULL,
HsAnswer varchar(55) COLLATE utf8_unicode_ci NOT NULL,
HsStatus varchar(55) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Pending',
HsDateCreated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
HsPrize varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (HsID)
)";
级别列将具有 1 - 10 的整数。我想从 Qnlevel=1 的问题中选择一个随机问题,并且该问题以前一定没有被用户回答过。所以我有这个查询
//SELECT GAMERS question HISTORY
$result = mysql_query("SELECT HsQnID FROM #__QnHistory WHERE HsGamerID LIKE GamerID");
$Answeredquestions = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$Answeredquestions[] = $row['QnID'];
}
// I now select questions making sure the user hasent anweres them
$query="SELECT * FROM #__GmQuestions WHERE QnLevel = 1 AND QnID NOT IN ('.implode(',', $Answeredquestions).')";
我的大问题是我需要从这些选定的问题中选择一个随机问题。我的数据库多达 600,000 个问题,我在大型数据库上看到了一些关于 rand() 的投诉。艾米想出如何只选择一个用户尚未回答的随机问题。我仍在开发中,因此欢迎所有回答,即使这意味着要更换我的桌子