Randomized "Links" list

Page 1 of 1

0 Replies - 481 Views - Last Post: 02 September 2006 - 11:24 AM

#1 wzeller   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 85
  • Joined: 09-April 06

Randomized "Links" list

Posted 02 September 2006 - 11:24 AM

Description: Update the first couple lines to specify your host, username, password, and database name. (Better yet, move the mysql_connect line to an external file outside your web directory structure and call it with an include.)

Store your links in a database table called "links" (or change the table name in the snippet). The links table should have fields for the link, title, and descriptive paragraph. Also, a 'status' field set to 'ACTIVE' for each record you want to include.

Put this snippet whereever it is on your page that you want the link list to appear.

An example of this snippet in use can be found at http://www.miraclebl...t.com/links.htm

WDo you have a page of links on your site?

How do you order them? Alphabetically? Chronologically? However it is, the links at the bottom of the list get the short end of the stick.

Store your links in a database table and display them in a random order with every page load. Now everybody gets a fair share of time at the top of the list!
   $db = mysql_connect("localhost", "username", "password");
    mysql_select_db("dbname",$db) or die("Couldn't Connect To Database.");
    $query = "select link, title, paragraph from links where upper(status)='ACTIVE' ORDER BY RAND() ";
    $result = mysql_query($query);
    $numrows = mysql_numrows($result);
    for($i = 0; $i < $numrows; $i++) {
       $link = mysql_result($result,$i,0);
       $title = mysql_result($result,$i,1);
       $paragraph = mysql_result($result,$i,2);
       print "<p><a target='linkwindow' href='http://$link'>$title</a>: $paragraph </p>";

Is This A Good Question/Topic? 0
  • +

Page 1 of 1