You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 68 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Random Members Block [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
CodyG
Private
Private


Joined: Jan 13, 2003
Posts: 46

Location: Canada

PostPosted: Sat Feb 08, 2003 4:29 pm Reply with quoteBack to top

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>';

while ($myrow = mysql_fetch_array($result)) {

printf("<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s<br>\n",
$myrow["user_avatar"], $myrow["uname"], $myrow["url"], $myrow["user_avatar"], $myrow["user_from"], $myrow["user_interest"]);
}

//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
Find all posts by CodyGView user's profileSend private message
Zhen-Xjell
Nuke Cops Founder
Nuke Cops Founder


Joined: Nov 14, 2002
Posts: 5939


PostPosted: Sat Feb 08, 2003 6:36 pm Reply with quoteBack to top

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)) {

printf("<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s<br>\n",
$myrow["user_avatar"], $myrow["uname"], $myrow["url"], $myrow["user_avatar"], $myrow["user_from"], $myrow["user_intrest"]);
}

//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]
Find all posts by Zhen-XjellView user's profileSend private messageSend e-mailVisit poster's website
CodyG
Private
Private


Joined: Jan 13, 2003
Posts: 46

Location: Canada

PostPosted: Sat Feb 08, 2003 7:42 pm Reply with quoteBack to top

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
Find all posts by CodyGView user's profileSend private message
CodyG
Private
Private


Joined: Jan 13, 2003
Posts: 46

Location: Canada

PostPosted: Mon Feb 10, 2003 10:27 am Reply with quoteBack to top

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
Find all posts by CodyGView user's profileSend private message
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
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



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.260 Seconds - 203 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::