Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Databases Code Examples

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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"; ?>