I'm hoping to create a block that displays member information randomly each time the page is refreshed.
I've used snippets of code from other blocks, modules, etc. that do work. You can see it not working at http://www.compytec.com, bottom left block called "testing." I'm only getting an empty block. Any ideas?
Code:
<?php
if (eregi("block-Random_Member.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
global $prefix, $uname, $url, $user_avatar, $user_from, $user_interest, $dbi;
// Create the random id for the user
$result = mysql_query("SELECT COUNT(*) FROM $prefix"._users."");
$users_count = mysql_fetch_array($result);
$users_count = $users_count[0];
// only proceed if we have user in the database
if ($users_count > 0) {
if ($users_count == 1) {
$random = 0;
} else {
srand((double)microtime()*1000000);
$random = rand(0,$users_count - 1);
}
// Now that we have the random number we can pull out the record
$result = mysql_query("SELECT * FROM $prefix"._users." LIMIT $random,1");
$myrow = mysql_fetch_row($result);
$content .= '<center><font class=content><i>';
//close the formatting
$content .= '</font></i></center>';
} else {
// this is what we say when the user database is empty
$content = "NoMoreUsers";
}
?>
_________________ "We want to see if life is ubiquitous" -Daniel Goldin
Zhen-Xjell Nuke Cops Founder
Joined: Nov 14, 2002
Posts: 5939
Posted:
Sat Feb 08, 2003 6:36 pm
Try this... (I took a short look):
Code:
<?php
if (eregi("block-Random_Member.php", $PHP_SELF)) {
Header("Location: index.php");
die();
}
global $prefix, $uname, $url, $user_avatar, $user_from, $user_interest, $dbi;
// Create the random id for the user
$result = mysql_query("SELECT COUNT(uid) FROM ".prefix."_users", $dbi);
$users_count = mysql_fetch_array($result);
$users_count = $users_count[0];
// only proceed if we have user in the database
$random = 0;
if ($users_count) {
srand((double)microtime()*1000000);
$random = rand(0,$users_count - 1);
}
// Now that we have the random number we can pull out the record
$result = mysql_query("SELECT user_avatar, uname, url, user_from, user_intrest FROM ".$prefix."_users LIMIT $random,1", $dbi);
$myrow = mysql_fetch_row($result);
$content .= '<center><font class=content><i>';
while (list($user_avatar, $uname, $url, $user_from, $user_intrest) = mysql_fetch_array($result)) {
//close the formatting
$content .= '</font></i></center>';
} else {
// this is what we say when the user database is empty
$content = "NoMoreUsers";
}
?>
_________________ Paul Laudanski, Microsoft MVP Windows-Security
CastleCops: [de] [en] [wiki]
CodyG Private
Joined: Jan 13, 2003
Posts: 46
Location: Canada
Posted:
Sat Feb 08, 2003 7:42 pm
At first I was getting a syntax error in that else statement at the bottom. So I removed it. Now:
Warning: Supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/compytec.com/httpdocs/blocks/block-Random_Member.php on line 13, in this bit.
Code:
// Create the random id for the user
$result = mysql_query("SELECT COUNT(uid) FROM ".prefix."_users", $dbi);
$users_count = mysql_fetch_array($result);
$users_count = $users_count[0];
Could the result be not valid because of empty fields?
_________________ "We want to see if life is ubiquitous" -Daniel Goldin
CodyG Private
Joined: Jan 13, 2003
Posts: 46
Location: Canada
Posted:
Mon Feb 10, 2003 10:27 am
How difficult could this block be?? Am I missing something obvious or just clueless.
Does it make sense to develop the block output first, then, once that works, add the code to make it random? Or should it be a more organic process, one doesn't work without the other?
The random isn't working. Warning: Supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/compytec.com/httpdocs/blocks/block-Random_Member.php on line 13, in this bit.
[code]
global $prefix, $uname, $url, $user_avatar, $user_from, $user_intrest, $dbi;
// Create the random id for the user
$result = mysql_query("SELECT COUNT (uid) FROM ".prefix."_users", $dbi);
/* 13 */ $users_count = mysql_fetch_array($result);
$users_count = $users_count[0];
// only proceed if we have user in the database
$random = 0;
if ($users_count) {
srand((double)microtime()*1000000);
$random = rand(0,$users_count - 1);
}
_________________ "We want to see if life is ubiquitous" -Daniel Goldin
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