How about using the rand() function built into
MySQL? You could use it to generate a random number, then find the row whose
primary key equals that random number, then do a single-row select on that
row.
Rhino
----- Original Message -----
Sent: Tuesday, April 26, 2005 11:33
AM
Subject: Get a Random Row on a HUGE
db
I am wanting to
display a random page from my site, But I have over 12,000 articles right now
and we add over 150 per day. What I wound up doing was a Virtual DOS
attack on my own server because the 40 mb db was being loaded to many
times.
I have tons of
memory and a Dell Dual Xeon 2.8 gig.
Can someone think
up a better way of doing this? I wish Mysql would just bring me back 1
valid random row It could be used in so many ways it should just be a
part of MySql anyway.
<?php ini_set("display_errors",
'1'); header("Pragma: private"); header("Cache-Control: post-check=0,
pre-check=0", false); header("Cache-Control: no-cache,
must-revalidate"); require_once("firebase.conf.php"); $dbi = new
DBI(DB_URL); $stmt = "Select * from firebase_content Order By rand() DESC
Limit 0, 1"; $result = $dbi->query($stmt); while($row =
$result->fetchRow()) { $title = $row->title; $cate
= $row->category; $get = "Select cat_url from firebase_categories
where cat_name='$cate'"; $now = $dbi->query($get); $rows
= $now->fetchRow(); $url = ""> $link =
$url . $title; } header("Location: http://www.prnewsnow.com/$link"); exit; /*
Sudo code that I am trying to create to relieve server stress. function
randomRow(table, column) { var maxRow = query("SELECT MAX($column) AS maxID
FROM $table"); var randomID; var randomRow; do { randomID =
randRange(1, maxRow.maxID); randomRow = query("SELECT * FROM $table WHERE
$column = $randomID"); } while (randomRow.recordCount == 0); return
randomRow; } */ ?>
No virus found in this incoming message. Checked by AVG
Anti-Virus. Version: 7.0.308 / Virus Database: 266.10.2 - Release Date:
21/04/2005
|
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.2 - Release Date: 21/04/2005
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]