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 7778271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:21:22+00:00 2026-06-01T18:21:22+00:00

What I want to do is to display 5 random images with text out

  • 0

What I want to do is to display 5 random images with text out of a certain number without repeating. The links to images and the texts are to be stored in the database. The issue I’ve run into is I need to put every ID value into the single PHP array in order to shuffle the IDs and pick random 5, yet I keep failing in combining them into a single array, if I have 3 rows I end up with 3 arrays.

This is an example of a failing code with 3 rows with ID 1,2,4:

function getAll () {
$query = mysql_query("SELECT * FROM ads") or die(mysql_error());
$myarray = array();
    while ($numbers = mysql_fetch_array($query)){
    $arr = $numbers['ID'].",";
    print_r (explode(",", $arr));
    }
};

This is the output:

Array ( [0] => 1 [1] => ) Array ( [0] => 2 [1] => ) Array ( [0] => 4 [1] => )

This is the desired output:

Array ( [0] => 1 [1] => 2 [2] => 4)

Guess it’s a noob question but I’ve done my best in trying to find the solution and failed.

  • 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-01T18:21:24+00:00Added an answer on June 1, 2026 at 6:21 pm

    Easy solution: Shuffle the result directly by using ORDER BY RAND() in your MySQL query:

    SELECT * FROM ads ORDER BY RAND() LIMIT 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I want to do is display three random images from a database. I
I want to display a random record from the database for a certain amount
I want a web page to display several random images on load. I've thought
I have a database full of images, and I want to spit out and
HI, I want to display 20 random images at a time over Activity screen
I want to select four random images from a folder which contains a number
I have an array of images that I want to display in a random
I have a smarty template, that I want to display a random sentence on
I want display data from database in Listbox...Here is my code, It is not
I want to display images in a TableView . I can display one image

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.