Mega Code Archive

 
Categories / Php / MySQL Database
 

I`d like to use the mysql_fetch_row function along with a randomizer

function that would give me a random result from a mySQL table <? srand(date("s")); $result = mysql_db_query("frizbcd","SELECT cd_id FROM CD_Table",$linkid); $rnum = rand() % mysql_numrows($result); $sql ="SELECT cd_id,artist_title,upc FROM CD_Table WHERE cd_id = "; $sql .= mysql_result($result,$rnum,"cd_id"); $result = mysql_db_query("frizbcd",$sql,$linkid); echo "<TABLE BORDER=\"1\" BGCOLOR=\"#000000\" CELLPADDING=\"10\" CELLSPACING= \"0\">"; $artisttitle = split("/",mysql_result($result,$ridx,"artist_title")); echo "<TR Align=\"CENTER\"><TD><FONT FACE=\"Verdana, Arial, Helvetica\" SIZE=- 2> Do you have this CD by <B>$artisttitle[0]</B> in YOUR collection?<P>"; $image = "cdimages/".strtolower(mysql_result($result,0,"upc")).".gif"; if (file_exists($image)) { echo "<IMG SRC=\"$image\"><P>"; } echo "<FORM Action=\"show.phtml\" Method=\"Post\">"; echo "<INPUT Name=action Type=Submit Value=\"$artisttitle[1]\">"; echo "<INPUT Name=ID Type=hidden Value=\"".mysql_result($result,0,"cd_id")."\"> </FORM></FONT></TD></TR></TABLE><P>"; echo $totalcds," CDs currently in the database"; ?>