cryp7 Posted November 24, 2006 Share Posted November 24, 2006 Hi,The code I have so far is:[code]<?phpmysql_connect("localhost", "HIDDEN", "HIDDEN") or die(mysql_error());mysql_select_db("HIDDEN") or die(mysql_error());$category = games;$totalrows = mysql_query("SELECT * FROM games");or die(mysql_error());$totalrowsresult = mysql_num_rows($totalrows);or die(mysql_error());srand ((double) microtime( )*1000000);$randnum = rand(1,'$totalrowsresult');or die(mysql_error());$result = mysql_query("SELECT * FROM games WHERE no='randnum'");while($row = mysql_fetch_array($result))or die(mysql_error());echo "$row['no'], $row['id'], $row['data']";or die(mysql_error());?>[/code]What i want it to do is to count the number of rows in the table "games" then select a random number between 1 and how ever many rows there are in the table, then to select the data from the row, where the random number is equal to the value "no" in a row of the "games" table. Then finally to display this infomation.Ive written the above and am unsure whats wrong...The error i get is[quote]Parse error: syntax error, unexpected T_LOGICAL_OR in HIDDEN/select.php on line 9[/quote]Any help I could get would greatly be appreciated.Thanks in advancedAndy Link to comment https://forums.phpfreaks.com/topic/28334-php-and-mysql-help/ Share on other sites More sharing options...
printf Posted November 24, 2006 Share Posted November 24, 2006 Why not just...[code]$result = mysql_query ( "SELECT * FROM games ORDER BY RAND() LIMIT 1" );$row = mysql_fetch_assoc ( $result );// do stuff[/code]printf Link to comment https://forums.phpfreaks.com/topic/28334-php-and-mysql-help/#findComment-129599 Share on other sites More sharing options...
kenrbnsn Posted November 24, 2006 Share Posted November 24, 2006 You have extra and illegal "or die" clauses scattered throughout your code.Ken Link to comment https://forums.phpfreaks.com/topic/28334-php-and-mysql-help/#findComment-129610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.