Hangman php来自数据库的新随机词

时间:2015-07-02 20:50:10

标签: php mysql

我正在制作一个刽子手游戏,但我想从我的数据库中选择一个随机单词。

数据库连接:

     $db_host               = "127.0.0.1"; 
     $db_user               = "root";
     $db_pass               = "";
     $db_table          = "galgje";

    $db = mysql_connect($db_host,$db_user,$db_pass);
    mysql_select_db($db_table,$db);
    $query = "SELECT word FROM dba_tblwords " ;
    $select = @mysql_query($query);

while($row = mysql_fetch_array(($select)))

{
$list = ($row['word']);
}

选择一个新词:

 if ($wrong >= $max)
 {
SELECT word FROM dba_tblwords ORDER BY RAND() LIMIT 0,1  
} 

这不起作用。谁能帮帮我?

1 个答案:

答案 0 :(得分:0)

您应该使用此查询

SELECT word FROM dba_tblwords ORDER BY RAND() LIMIT 1

并传递到数据库。请记住,rand()的顺序性能很低。为了更好地理解,请参阅this answer