Re: Pulling random HTML code out of a table

From: Date: Wed, 03 Jan 2001 19:10:56 +0000
Subject: Re: Pulling random HTML code out of a table
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-5579@lists.php.net to get a copy of this message
I have this code that i use to get a random news articel from the database, but looks like what you might need also. <!-- Begin Code --> $query = mysql_query("Select count(*) from news"); $rs = mysql_fetch_row($query); $num = $rs[0]; function random_article(){ global $num; srand((double)microtime() * 1000000); $random = rand("0",$num); $id = mysql_query("Select * from news where record_number='$random'"); $article = mysql_fetch_object($id); if(!$article) random_article(); $entry["title"] = $article->title; $entry["text"] = strip_tags(trim(substr($article->entry, 0, 95)))."..."; // This just grabs a snippet from the cell. you might delete this $entry["id"] = $random; return $entry; } $one = random_article(); ?> <table width="129" border="0" cellspacing="0" cellpadding="0" height="145"> <tr valign="top"> <td valign="top" height="29"> <div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#CCCC00"> <A HREF="/news/kb.php3?article=<?=$one["id"]?>"><?=$one["title"]?></font></b></ div><BR> </A></td> </tr> <tr valign="top"> <td valign="top"><font face="Arial, Helvetica, sans-serif" size="2"> <?PHP echo $one["text"]; ?></font> <BR><div align="center"><font face="Arial, Helvetica, sans-serif" size="1"> <A HREF="/news/kb.php3?article=<?=$one["id"]?>">More. . . </a></div> </font></td> </tr> </table> ----- Original Message ----- From: "Cal Evans" <cal@calevans.com> To: "Mattias Johansson" <smart@smartsmartsmart.com>; <php-db@lists.php.net> Sent: Wednesday, January 03, 2001 11:06 AM Subject: RE: [PHP-DB] Pulling random HTML code out of a table > In psuedo code: > > Find the maximum CodeID. > Pick a number between 1 & maxCodeID > Select * from tableName where codeID =$selectedCodeID > ... > you know the rest. > > I would use PHP to pick the random number. (IMHO) > > Cal > > > -----Original Message----- > From: Mattias Johansson [mailto:smart@smartsmartsmart.com] > Sent: Wednesday, January 03, 2001 11:38 AM > To: php-db@lists.php.net > Subject: [PHP-DB] Pulling random HTML code out of a table > > > Okay, this is the scenario: > I have a table with two columns. One called CodeID and one called code. In > the code column is HTML code. (duh) > Now, I want to create a query which chooses a random CodeID and pulls out > the code associated with it. I then simply echo the code unto the web page. > How do I make the query? > > Really, really thankful for an answer! > > /Mattias > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#5579) next »