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

  • Home
  • SEARCH
  • 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 9008781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:01:28+00:00 2026-06-16T02:01:28+00:00

I want to loop through the values of array which contain $i variable in

  • 0

I want to loop through the values of array which contain $i variable in it,

My code for array looks like this,

foreach($fields_names as $k => $v) {
      $handle_data[] ='$rowdata[$i][$fields_names[\''.$v.'\']]';
}

for($i=0;$i<$number_rows_excel;$i++){

$sql.= "('".implode("','", array_values($handle_data))."'),". "<br/>";

        }

When I am echoing $sql, I am getting like this ,

INSERT INTO eximport (`S.No`, `Patent#`, `Title`) VALUES ('$rowdata[$i][$fields_names['S.No']]','$rowdata[$i][$fields_names['Patent#']]','$rowdata[$i][$fields_names['Title']]')

It should have to display like this

INSERT INTO eximport (`S.No`, `Patent#`, `Title`) VALUES ('$rowdata[0][$fields_names['S.No']]','$rowdata[0][$fields_names['Patent#']]','$rowdata[0][$fields_names['Title']]')

How can I use the variable $i to loop through array values?

  • 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-16T02:01:30+00:00Added an answer on June 16, 2026 at 2:01 am

    i have used this code which helps me to insert the row, appending ‘,’ for each values for insert

     foreach($val_ary as $new_data_string){
        $newArray[] = implode("','",$new_data_string);
            }
    
    //Inserting data into the table     
            for($tr=0;$tr< $data->sheets[0]['numRows']-2;$tr++)
            {
             $sql ="INSERT INTO eximport($fieldnames)values('$newArray[$tr]')";
             mysql_query($sql) or die("Error in Query: " . mysql_error());  
             //$p1 = $db->insert_id;
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C, I want to loop through an array in this order for(int z
I want to loop through an array with foreach to check if a value
I have the below but want to only loop through lines in #lines which
I have the following code which loops through an array to create forms that
I've got a loop which goes through various products being imported. Within this loop
I am trying to loop through an array and replace values that are in_array
I want to loop through the checkboxgroup 'locationthemes' and build a string with all
I want to loop through the controls on a UserControl and set a property
I want to loop through a database of documents and calculate a pairwise comparison
I want to loop through the rows of a data.table and calculate an average

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.