Free Press Release Submission




MB Publishing Webmaster Resource ::
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin 


Random Links Block

 
Post new topic   Reply to topic    MB Publishing Webmaster Resource Forum Index -> Nuke Blocks
View previous topic :: View next topic  
Author Message
Colocation
Site Admin
Site Admin


Joined: Jan 07, 2004
Posts: 412

PostPosted: Tue Apr 13, 2004 10:28 pm    Post subject: Random Links Block Reply with quote

How can this code be made to display random links as opposed to the top 10?

Code:
<?php

if (eregi("block-Top10_Links_test.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db;

$a = 1;
$sql = "SELECT lid, title FROM ".$prefix."_links_links ORDER BY hits DESC LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$transfertitle = str_replace (" ", "_", $row[title]);
    $title2 = ereg_replace("_", " ", $row[title]);
    $content .= "<strong><big>·;</big></strong> ;;$a: <a href=\"viewlinkdetails-$row[lid]-$transfertitle.html\">$title2</a><br>";
    $a++;
}

?>
Back to top
View users profile Send private message Visit posters website Yahoo Messenger
Humpa
Site Admin
Site Admin


Joined: Feb 05, 2004
Posts: 23

PostPosted: Thu Apr 15, 2004 10:39 am    Post subject: Reply with quote

Code:
<?php

if (eregi("block-Top10_Links_test.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db;
$rand_num_array = array();
$total_links = $db->sql_num_rows(sql_query("select * from ".$prefix."_links_links"));

$a = 1;
while($a <= 10) {
   mt_srand((double)microtime()*1000000);
   $rand_num = mt_rand(0,($total_links-1));
   if(!in_array($rand_num,$rand_num_array)) {
      $rand_num_array[] = $rand_num;
      $sql = "SELECT lid, title FROM ".$prefix."_links_links DESC LIMIT $rand_num,1";
      $result = $db->sql_query($sql);
      $row = $db->sql_fetchrow($result);
      $transfertitle = str_replace (" ", "_", $row[title]);
      $title2 = ereg_replace("_", " ", $row[title]);
      $content .= "<strong><big>·;</big></strong> ;;$a: <a href=\"viewlinkdetails-$row[lid]-$transfertitle.html\">$title2</a><br>";
      $a++;
   }
}

?>

I think that will work.
Give it a try and let me know. icon_biggrin.gif
Back to top
View users profile Send private message Visit posters website
Colocation
Site Admin
Site Admin


Joined: Jan 07, 2004
Posts: 412

PostPosted: Thu Apr 15, 2004 5:19 pm    Post subject: Fatal Error Reply with quote

Thanks.

Getting this:

Code:
Fatal error: Call to undefined function: sql_num_rows() in /usr/www/virtual/filtered/www.blocktest.com/blocks/block-Top10_Links_test.php on line 10


Line 10 is this:

Code:
$total_links = $db->sql_num_rows(sql_query("select * from ".$prefix."_links_links"));
Back to top
View users profile Send private message Visit posters website Yahoo Messenger
Humpa
Site Admin
Site Admin


Joined: Feb 05, 2004
Posts: 23

PostPosted: Thu Apr 15, 2004 7:00 pm    Post subject: Reply with quote

Sorry .. it should be sql_numrows
Back to top
View users profile Send private message Visit posters website
Colocation
Site Admin
Site Admin


Joined: Jan 07, 2004
Posts: 412

PostPosted: Thu Apr 15, 2004 10:19 pm    Post subject: Further Steps Reply with quote

I tried this updated code as you suggested:

Code:
<?php

if (eregi("block-Top10_Links_test.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}

global $prefix, $db;
$rand_num_array = array();
$total_links = $db->sql_numrows(sql_query("select * from ".$prefix."_links_links"));

$a = 1;
while($a <= 10) {
   mt_srand((double)microtime()*1000000);
   $rand_num = mt_rand(0,($total_links-1));
   if(!in_array($rand_num,$rand_num_array)) {
      $rand_num_array[] = $rand_num;
      $sql = "SELECT lid, title FROM ".$prefix."_links_links DESC LIMIT $rand_num,1";
      $result = $db->sql_query($sql);
      $row = $db->sql_fetchrow($result);
      $transfertitle = str_replace (" ", "_", $row[title]);
      $title2 = ereg_replace("_", " ", $row[title]);
      $content .= "<strong><big>·;</big></strong> ;;$a: <a href=\"viewlinkdetails-$row[lid]-$transfertitle.html\">$title2</a><br>";
      $a++;
   }
}

?>


Which now gives this:

Code:
Warning: Missing argument 2 for sql_query() in /usr/www/virtual/filtered/www.blocktest.com/includes/sql_layer.php on line 176

Fatal error: Maximum execution time of 30 seconds exceeded in /usr/www/virtual/filtered/www.blocktest.com/blocks/block-Top10_Links_test.php on line 16


Thanks! icon_biggrin.gif
Back to top
View users profile Send private message Visit posters website Yahoo Messenger
Humpa
Site Admin
Site Admin


Joined: Feb 05, 2004
Posts: 23

PostPosted: Fri Apr 16, 2004 4:32 am    Post subject: Reply with quote

The problem is that I never use phpnuke's method of retrieving data using mysql, so I couldn't test it. This seems like a slow process (having you test it icon_confused.gif ).
So, I switched the code to the normal mysql functions, and I tested it.

Code:
<?php
if (eregi("block-Top10_Links_test.php",$_SERVER['PHP_SELF'])) {
    Header("Location: index.php");
    die();
}
$num_of_links = 10;
global $prefix;
$rand_num_array = array();
$total_links = mysql_num_rows(mysql_query("select * from ".$prefix."_links_links"));
if($total_links < $num_of_links) {
   $num_of_links = $total_links;
}
$a = 1;
while($a <= $num_of_links) {
   mt_srand((double)microtime()*1000000);
   $rand_num = mt_rand(0,($total_links-1));
   if(!in_array($rand_num,$rand_num_array)) {
      $rand_num_array[] = $rand_num;
      $result = mysql_query("SELECT lid, title FROM ".$prefix."_links_links ORDER BY hits DESC LIMIT $rand_num,1");
      $row = mysql_fetch_row($result);
      $transfertitle = str_replace (" ", "_", $row[1]);
      $title2 = ereg_replace("_", " ", $row[1]);
      $content .= "<strong><big>·</big></strong> $a: <a href=\"viewlinkdetails-$row[0]-$transfertitle.html\">$title2</a><br>";
      $a++;
   }
}
?>
Back to top
View users profile Send private message Visit posters website
Colocation
Site Admin
Site Admin


Joined: Jan 07, 2004
Posts: 412

PostPosted: Fri Apr 16, 2004 7:55 am    Post subject: For The Record Reply with quote

Now that is a beautiful block....

And the thing is, it presents ever changing content to a search engine bot.

icon_biggrin.gif
Back to top
View users profile Send private message Visit posters website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    MB Publishing Webmaster Resource Forum Index -> Nuke Blocks All times are GMT + 1 Hour
Page 1 of 1

 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Home | News Feeds | Release Archive | Web Marketing | Weight Loss | Publish Your Links | Press Release Topics | Free Downloads | Press FAQs | AvantGO | Amazon Store
Webmaster Forums | Search Releases | Press Topics | Feedback | Submit Press Release | Webmaster Surveys | Recommend | Top | Account | PM | Prweb | Free Link Submission | Add Downloads | New Media | Audio School | TOS

The comments are property of their posters, all the rest 2004 - 2008 by MB
Audana Ltd
You can syndicate our news using the file backend.php
Web site engine's code is Copyright © 2003 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.901 Seconds. -