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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:35:25+00:00 2026-05-28T05:35:25+00:00

The value for $i in the code below is always 2. It seems it

  • 0

The value for $i in the code below is always 2. It seems it increments to the first time, but only that time. Any thoughts?

 foreach ($records as $row){

    $i = 1;
    $i++

    if ($i % 2 != 0){
        $trClass = 'odd';               
    }else{
        $trClass = 'even';
    }

    echo '<tr class="' . $trClass . '"><td>' . 
        anchor("admin/delete/$row->id", 'delete') . '</td><td>' . 
        anchor("admin/edit/$row->id", 'Edit') . '</td>';

    foreach ($row as $key => $value){
        echo '<td>' . $value . '</td>';
    }

    echo '</tr>';
    $i++;
}
  • 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-05-28T05:35:26+00:00Added an answer on May 28, 2026 at 5:35 am

    You’re reassigning it to 1 every time through the loop. Initialize it outside the loop instead.

    $i = 1;
    foreach ($records as $row){
        /*
         ...
        */
    
        $i++;
    }
    

    Also I see that you’re incrementing both at the beginning of the loop and at the end. I assume you only want to do it once (probably keep only the one at the end; remove the one at the beginning).

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

Sidebar

Related Questions

The code below takes an array value, if it's key exist it should echo
From the code below I am getting a cell value from the selected row
The code below is working nearly flawlessly, however my value for page title on
I have the code below, which sends the value of the textarea and either
In the below code onclick edit how can the value of tag test be
IN JAVA CODE IN JSP as below i m getting null value for fieldnoOfRecords.
Below is a code snippet, where we retrieve a form value. Before further processing
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
I have difficulties calculating percentage of a double value. I wrote the code below
The code below outputs Japan Standard Time. TimeZone tz = TimeZone.getTimeZone(Asia/Tokyo); Locale locale =

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.