friendspimp Posted July 2, 2009 Share Posted July 2, 2009 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/164452-how-to-return-random-result-from-table-with-this-script/ Share on other sites More sharing options...
Philip Posted July 2, 2009 Share Posted July 2, 2009 http://www.phpfreaks.com/forums/index.php/topic,125759.0.html Link to comment https://forums.phpfreaks.com/topic/164452-how-to-return-random-result-from-table-with-this-script/#findComment-867491 Share on other sites More sharing options...
friendspimp Posted July 2, 2009 Author Share Posted July 2, 2009 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? Link to comment https://forums.phpfreaks.com/topic/164452-how-to-return-random-result-from-table-with-this-script/#findComment-867502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.