Jump to content

How to return random result from table with this script....


friendspimp

Recommended Posts

I am trying to return a random result based on the 'featured_end' value of this query... I anticipate that I will have several thousand rows in the future... basically I want this to return a random result everytime a user refreshes the page or every 2 minutes as not to overload the server and slow it down... I have tried many variations... just can't seem to get something to work.

 

 

<?php
//Init database connection
$app = getApp();
$client = $app->getMySqlClient();
$client->connect();              
$table_prefix = $app->getIni("MySql", "table_prefix");
$table_partisipant = $table_prefix."participant";
//Select information
$featured_users_limit = $app->getIni('Application', 'featured_users_limit');
$client->query("SELECT id, points FROM $table_partisipant ORDER BY featured_end DESC LIMIT {$featured_users_limit} OFFSET 0");

#$client->query("SELECT id, points, featured_end FROM $table_partisipant ORDER BY RAND() LIMIT 0,1");

$ids = array();
$points = array();
for($i = 0; $i < $featured_users_limit; $i++)
{
    $ids[$i] = '';
    $points[$i] = '';
}                                                        
$i = 0;
while($result = $client->fetchAssoc()) 
{ 
    $ids[$i] = $result['id'];
    $points[$i] = $result['points'];
    $i++;
}
if($error = $client->close())
    $app->reportError($error);
$rows_count = ceil($featured_users_limit / ;
if($i > 0)
{
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td colspan='10' align='center'><font class='header-text'><br>Our VIP Users!<br><br></font></td></tr>";
    $row = 0;
    while($row < $rows_count)
    {    
        echo "<tr>";
        for($i = 0; $i < 8; $i++)
        {
            $id = @$ids[$i + $row * 8];
            $pt = $points[$i + $row * 8];
            if($id == '')
            {
                echo "<td width='20%' align='center' valign='top'></td>";
            }
            else
            {
                $page = GetProfileHtml($id); 
                //Get name
                $name = GetProfileName($page);
                //Get image
                $photo = GetProfileImage($page, $id);
               echo "<td width='12.5%' align='center' valign='top'><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr valign='top' align='center'><td height='100'><a href='http://www.myspace.com/$id' target='_blank'><img src='$photo' alt='' border='0'></a></td></tr><tr valign='top' align='center'><td><font class='plain'><!--$name (<span style='color: blue;'>$pt points</span>)--></font></td></tr></table><br></td>";
            }
        }
        $row++;
        echo "</tr>";
    }
    echo "</tr></table>";
}
?>

I really do appreciate the link... I am just so new at php and mysql that I am not sure how to integrate this with my code as posted and get it to work correctly.. maybe someone can give me a hand here and show me what I need to do then I can use this as a tutorial for future reference?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.