Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > modules/random-links.inc.php
<%

	$con = mysql_connect();
	mysql_selectdb( getDBName() );
	$qs = "SELECT COUNT(*) FROM links";
	$q = mysql_query( $qs );
	if( $q ) {
		$count = mysql_result($q,0);

		# we pick twice as many as we need, 
		# to allow for skipping private links, 
		# and holes in the link ID space
		$numPicks = 6; 

		for( $i = 0; $i < $numPicks; $i++ ) {
			$picks[$i] = rand( 1, $count );
		}
%>
<div id="random" class="box">
	<div class="subhead">
		<%= count( $picks ) / 2 %> random links:
	</div>
<%
		foreach( $picks as $randomLink ) {
			if( isValidLink( $randomLink ) && !isPrivate( $randomLink ) && $linksPrinted < 3 ) {
				$linksPrinted++;
%>
<div class="r<%= $linksPrinted % 2 == 0 ? 1 : 0 %>">
<%= makeUserLink( getOwnerForLink( $randomLink )) %>'s <%= makeLinkOut( $randomLink ) %> <%= makePermaLink( $randomLink ) %>
</div>
<%
			}
		}
%>
</div>
<%
	}
	mysql_close( $con );
%>
Return current item: FeedMeLinks, Social BookmarkingSince2002