MB Publishing Webmaster Resource ::
View previous topic :: View next topic
Author
Message
Colocation Site Admin Joined: Jan 07, 2004 Posts: 412
Posted: Tue Sep 21, 2004 9:29 am Post subject: Randomise block-Top10_Downloads.php
How can we randomise the following block-Top10_Downloads.php block:
Code:
if (eregi("block-Top10_Downloads.php",$_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
global $prefix, $db;
$a = 1;
$sql = "SELECT lid, title FROM ".$prefix."_downloads_downloads ORDER BY hits DESC LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$title2 = ereg_replace ("_", " ", $row[title]);
$transfertitle = str_replace(" ", "_", $row[title]);
$content .= "<strong><big>·;</big></strong> ;;$a: <a href=\"downloadview-details-$row[lid]-$transfertitle.html\">$title2</a><br>";
$a++;
}
Back to top
Humpa Site Admin Joined: Feb 05, 2004 Posts: 23
Posted: Wed Sep 22, 2004 2:34 pm Post subject:
Try this:
Code:
if (eregi("block-Top10_Downloads.php",$_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
global $prefix, $db;
$a = 1;
$sql = "SELECT lid, title FROM ".$prefix."_downloads_downloads ORDER BY RAND() LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$title2 = ereg_replace ("_", " ", $row[title]);
$transfertitle = str_replace(" ", "_", $row[title]);
$content .= "<strong><big>·;</big></strong> ;;$a: <a href=\"downloadview-details-$row[lid]-$transfertitle.html\">$title2</a><br>";
$a++;
}
Back to top
Colocation Site Admin Joined: Jan 07, 2004 Posts: 412
Posted: Wed Sep 22, 2004 2:47 pm Post subject: Charming
Works like a charm, thanks!
I took out the highlighted bits, cause they looked ugly.
Quote:
if (eregi("block-Top10_Downloads.php",$_SERVER['PHP_SELF'])) {
Header("Location: index.php");
die();
}
global $prefix, $db;
$a = 1;
$sql = "SELECT lid, title FROM ".$prefix."_downloads_downloads ORDER BY RAND() LIMIT 0,10";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$title2 = ereg_replace ("_", " ", $row[title]);
$transfertitle = str_replace(" ", "_", $row[title]);
$content .= "<strong><big>·; </big></strong> ;; $a: <a href=\"downloadview-details-$row[lid]-$transfertitle.html\">$title2</a><br>";
$a++;
}
Back to top
Humpa Site Admin Joined: Feb 05, 2004 Posts: 23
Posted: Wed Sep 22, 2004 4:04 pm Post subject:
... you're welcome : )
I had actually never used the Rand() in a mysql_query before - not sure why, since that is a handy way to get a random result.
Back to top
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