Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:25:00+00:00 2026-06-05T11:25:00+00:00

I have a banners table which has image names and paths to image files

  • 0

I have a “banners” table which has image names and paths to image files that will be randomly viewed each time visitor navigates to another page.

banners table consists of banner_id (auto_increment, unique, primary, tinyint), banner_name (varchar) and banner_path (varchar) fields.

Banners table will be editable via a control panel. New banners will be ADDED, some banner will be DELETED after a while, and may be UPDATED. General CRUD operations, you know…

Now… Because of my goal is showing banners randomly, I will need a random number generator function which gives ability to exclude specific ones.

To be more clear,

Let’s say my table looks like this:

banner_id     banner_name     banner_path
---------     ------------    ------------
1             First Banner    first_banner.jpg
2             Second Banner   second_banner.jpg
3             Third Banner    third_banner.jpg

I can get random ID by using PHP function like this easily: mt_random(1, 3);

But wait. What if I delete one of these banners?

banner_id     banner_name     banner_path
---------     ------------    ------------
1             First Banner    first_banner.jpg
3             Third Banner    third_banner.jpg

In this case, as random output becomes “2”, what will happen? There is no a “2” banner_id’d row?? So I must exclude DELETED id’s from random generator number range. Will this be the best practise? If so, how can I do that?

I’m completly open for any new ideas which will help me to do thing I want to do.

Please help me to figure out this problem…

Thanks

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:25:02+00:00Added an answer on June 5, 2026 at 11:25 am

    Assuming you can live with the small race window, you could do

    SELECT FLOOR(RAND()*COUNT(*)) AS bannercount FROM banners;
    

    and fetch this into $bannercount, next run

    SELECT * FROM banners ORDER BY banner_id LIMIT $bannercount,1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with multiple rows, each row has: layout (select) images *
I have a niche site that I'd like to sell banners for directly, rather
SQL Server 2000. Single table has a list of users that includes a unique
I have 3 tables, images , icons , and banners , each with a
I have two flash banners (.swf) and i want to show them randomly on
I'm trying to build a page which will have a box-like layout..A top banner
I have a table in my MySQL database that looks like the following banner
I have a master page that gets all its images from a table on
I have a table of banners. Banners are marked with size id and slot
I have a javascript image gallery which is getting data from an XML file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.