mardi 4 août 2015

select a random row from my database table to use

I want to select a row randomly from 'puzzles' table and use its 'Pgn'. I tried this code but it didn't work. What's the error? and is there another way to do it?

 mysql_connect("localhost", "root");
 mysql_select_db("chess");
 $sql = mysql_query("SELECT Pgn FROM puzzles ORDER BY RAND() LIMIT 1");

 $pgn = mysql_fetch_array($sql);




Aucun commentaire:

Enregistrer un commentaire