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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:23:42+00:00 2026-06-03T18:23:42+00:00

I’m building a long query of dummy data. I have a for loop running

  • 0

I’m building a long query of dummy data. I have a for loop running a few thousand times, in each loop, it adds a new row to a query, with the increment variable used for dummy file names, 1.png, 2.png etc. I also need to increment a separate foreign key id, but it needs to only be every 10 iterations of the loop. can anyone help? Thanks.

$var = '';
for($i=0;$i<100;$i++){
    $path = '/test' . $i . '.pdf';
    $mess = 'Test message '. substr(md5($i), 0, 10);
    $did = 0;//How to increment this var by 1 every 10 iterations?
    $var .= "INSERT INTO `message` (`design_id`, `path`, `message`) VALUES ('$did', '$path', '$mess');"."<br />";
}
echo $var;
  • 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-03T18:23:43+00:00Added an answer on June 3, 2026 at 6:23 pm

    You can use the modulus operator:

    $did = 0;
    for($i=0;$i<100;$i++){
        $did += $i % 10 == 9;
    }
    

    The expression $i % 10 starts from 0, increases up to 9 (10 – 1) and then “wraps around” indefinitely. $did is increased every time it evaluates to 9, which is every 10 iterations.

    It’s interesting to note that you can use any value in the range [0, 9] for the comparison and it will still increase $did at the same rate; the difference is when the first increase will happen. By choosing 9 increases happen on the 10th, 20th, etc iteration. If you chose 0 instead, increases would happen on the 1st, 11th, 21st, etc.

    Finally, if this technique is new it might feel more comfortable to use extra parens, for example

    $did += ($i % 10 == 9);
    

    or even a standalone if statement.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.