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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:49:52+00:00 2026-06-06T05:49:52+00:00

I have the following php code: $k=1; for($i=0; $i < 5; $i++) { $stmt

  • 0

I have the following php code:

$k=1;
for($i=0; $i < 5; $i++)
{
    $stmt = $db->query('SELECT * FROM services_main');
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

        if ($row['ID'] == $i) {

            for($j=1; $j <= 3; $j++)
            {
                echo $row['name'].' - k='.$k++.' - j='.$j.' | ';
                echo $row['color'].' - k='.$k++.' - j='.$j.'<br />';

            }

        }
    }
}

This code generates this:

John - k=1 - j=1 | Blue - k=2 - j=1
John - k=3 - j=2 | Blue - k=4 -  j=2
John - k=5 - j=3 | Blue - k=6 -  j=3
Paul - k=7 - j=1 | Green - k=8 -  j=1
Paul - k=9 - j=2 | Green - k=10 -  j=2
Paul - k=11 - j=3 | Green - k=12 -  j=3
George - k=13 - j=1 | Red - k=14 -  j=1
George - k=15 - j=2 | Red - k=16 -  j=2
George - k=17 - j=3 | Red - k=18 -  j=3

I would like it to generate this:

John - k=1 - j=1 | Blue - k=1 - j=1
John - k=2 - j=2 | Blue - k=2 -  j=2
John - k=3 - j=3 | Blue - k=3 -  j=3
Paul - k=4 - j=1 | Green - k=4 -  j=1
Paul - k=5 - j=2 | Green - k=5 -  j=2
Paul - k=6 - j=3 | Green - k=6 -  j=3
George - k=7 - j=1 | Red - k=8 -  j=1
George - k=8 - j=2 | Red - k=8 -  j=2
George - k=9 - j=3 | Red - k=9 -  j=3
  • 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-06T05:49:53+00:00Added an answer on June 6, 2026 at 5:49 am

    The problem is whenever you make “$k++” you increment the $k value, and you are increasing it twice every round in the for loop, try to change to this:

    for($j=1; $j <= 3; $j++)
    {
        echo $row['name'].' - k='.$k.' - j='.$j.' | ';
        echo $row['color'].' - k='.$k.' - j='.$j.'<br />';
        $k++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP code: $data=mysql_query(SELECT * FROM notes WHERE rootNoteId='$noteId'); $mainArray; while($result
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>
I have the following php code: $k=1; for($i=0; $i < 5; $i++) { $stmt
I have the following PHP code which works out the possible combinations from a
I have the following PHP code doing a very simple select into a table.
I have the following PHP code to remove special characters from a variable; <?php
I have the following php code, post values are taken from a form- <?php
I have the following PHP code: echo ' <td id='.$metaso['semanaventa'].'td1><form id='.$metaso['semanaventa'].'form name='.$metaso['semanaventa'].'form class=dinamic action=compromiso_funciones.php
Hello I have the following php code, from the output $doc I want to
I have the following in php: public function myfunction($v){ //ini_set(memory_limit,32M); $v=mysqli_real_escape_string($this->connection,$v); $stmt=mysqli_prepare($this->connection,SELECT * from

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.