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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:33:37+00:00 2026-06-14T15:33:37+00:00

Im trying to assign a id for each image returned from the database. The

  • 0

Im trying to assign a id for each image returned from the database. The id will then be put into img id. The id needs to be from the total count of the number of database rows returned.

<?php 
while ($result  = mysql_fetch_assoc($query)) {
$imgURL = $result['imageUrl'];
$imgID = mysql_num_rows($query);

for ($i=0; $i <= $imgID; $i++) { 
}

echo"<img id =\"$i\" src=\"uploads/$imgURL\"/>";
}

?>

What i get in return is the images are displayed from the database, but instead of img id being sequential numbers (ie 1, 2, 3 etc.) it just returns me the total count. How can I get it to assign a individual number in order for each image returned?

All help is welcome. Thank you!

  • 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-14T15:33:38+00:00Added an answer on June 14, 2026 at 3:33 pm

    You don’t even need to calculate the number of rows or have multiple loops. Just let $i be incremented with each pass of the while loop.

    $i = 0;
    while ($result = mysql_fetch_assoc($query)) {
        $imgURL = $result['imageUrl'];
        echo '<img id ="' . $i . '" src="uploads/' . $imgURL . '" />';
        $i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am currently trying to assign each character that i get from a file
I'm trying to assign a function for each element in a loop. I would
I'm trying to assign integer to a newly created row: INSERT INTO wcategory (name,
I am trying to assign each button on the left its own Tab control.
I'm trying to ASSIGN dynamically exclusive meta-tags for each page: i.e: url.com/index.php?action=signup Header -
I am trying manipulate Jquery Infinite Carousel into dynamically resizing the image container based
i am trying to get id names from a array and trying to assign
I am trying to assign a different sound to each word in the listOfWords
I am trying to assign a block to a button object so that each
So i'm trying to assign a hyperlink to a single word in a {p}

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.