Project / Support Center
Welcome, Guest. Please login or register. July 04, 2022, 12:55: PM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  MySQL/PHP  |  Topic: Displaying Random Records in a recordset 0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: Displaying Random Records in a recordset  (Read 8590 times)
admin
Guest
« on: March 24, 2010, 06:56: PM »

mysql_select_db($database_wgncetv, $wgncetv);
$query_rsschoolicons = "SELECT * FROM School ORDER BY RAND() LIMIT 2,7";
$rsschoolicons = mysql_query($query_rsschoolicons, $wgncetv) or die(mysql_error());
$row_rsschoolicons = mysql_fetch_assoc($rsschoolicons);
$totalRows_rsschoolicons = mysql_num_rows($rsschoolicons);
?>
<table width="125" cellspacing="0" cellpadding="0">
    <?php do { ?> <tr>
          
               <td><img src="assets/schools/sitegrpahics/<?php echo $row_rsschoolicons['school_logo']; ?>" alt="" width="125" height="125" /> </td>
              <tr> <?php } while ($row_rsschoolicons = mysql_fetch_assoc($rsschoolicons)); ?>
      
</table>

The trick here is to not set the recordset limit but to let the query do it

LIMIT 2,7

The 2 or first # is to offset the starting place of the table record #
the 7 or second # is the number of records in to display.

This can be used for displaying ads which is what we did but it will not rotate them only display new ads each time the page loads.

another example

SELECT *
FROM photo_gallery
WHERE photo_gallery_1 = 1
ORDER BY RAND() LIMIT 0,20

Limit = limits the number of records to show

SELECT *
FROM photo_gallery
WHERE photo_gallery_1 = 1
ORDER BY RAND()

Will show all records randomly each time records load
« Last Edit: May 11, 2021, 05:19: PM by admin » Report to moderator   Logged
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  MySQL/PHP  |  Topic: Displaying Random Records in a recordset « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!