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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:35:19+00:00 2026-06-10T03:35:19+00:00

I created a while loop that produces random images for the user. Every time

  • 0

I created a while loop that produces random images for the user. Every time I load the page the while loop produces a random number of images. I would like for it to show 10 but it will produce anywhere from 3-10 images. I checked in the database and user_id is unique for every entry. I have no idea why it’s doing this. What is wrong with the code? I’ll also accept an answer that can point in a direction (tutorial link) to rewrite this code in a better way.

<?php

$query = mysql_query("SELECT `user_id` FROM  `users` ORDER BY RAND() LIMIT 0, 10");

$r = 1;

while ($results_row = mysql_fetch_assoc($query))

    {   

$var_1 = $results_row['user_id']; 

    $getting_essentials = mysql_query("SELECT 

    `band_name`,`donated_money`,`donated_time` FROM `create_project` WHERE `user_id` = 

    $var_1");

    $getting_results = mysql_fetch_assoc($getting_essentials);

$bandsname = $getting_results['band_name'];

if (isset($bandsname) === true) {       

$donatedmoney = $getting_results['donated_money'];

$donated_time = $getting_results['donated_time'];   

$var_2 = username_from_user_id($var_1); 

$image_name = 'images/' . md5($var_2) . '_' . $var_1;       

    echo '<a href="' . $var_2 . '"><img src="' . $image_name . '" class="'.$r.'" 

    width="300" height="185"/></a>';

} 
$r++;
}

?>
  • 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-10T03:35:21+00:00Added an answer on June 10, 2026 at 3:35 am

    I see a couple of potential problems.

    First, what is var_2? It doesn’t appear to be set anywhere.

    Second, it appears that you will get as many images as there are unique user IDs in your table. This seems to me a bizarre way of trying to get ten images.

    Third, the actual file names you’re using for the images are built using the user ID. It may well be that not all the files exist.

    A way to check that last point is to simply do a “View Source” operation in your browser.

    It may be that you’re always getting 123 images (assuming you have 123 distinct user IDs) but some of them don’t exist.

    As a low-level debugging exercise, you can insert code to echo debug statements (in HTML format) so you can see what’s happening under the covers. This is often the quickest way to determine problems. In other words, pepper your code with things like:

    $bandsname = $getting_results['band_name'];     # Existing line
    echo 'bandsname is "' . $bandsname . '".<br>';  # new line
    

    By doing that and examining the output, it’ll make it a lot more obvious than trying to do static analysis on the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a while loop that produces five images. I then designed the images
I have created a while loop that selects random images from from my server
A while back I created a lightbox plugin using jQuery that would load a
I created a while loop that produces multiple predefined circles on Google Maps. Each
I would like to get the id of a class that is created in
Can you create a line of code, within a while-loop, that will create a
I have created this function to check abecedarian with while loop (A word is
I am trying to construct an sql query using a while loop that increments
I have created a while loop while($row = mysql_fetch_Array($result)) { echo '<tr class=record> <td></td><td>'
I have a page that is creating dynamically created rows in a table with

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.