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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:31:36+00:00 2026-05-28T02:31:36+00:00

I have a bit of PHP code that’s baffling me for some reason. I

  • 0

I have a bit of PHP code that’s baffling me for some reason. I know that I need to iterate through the array and run a SQL query for each value in the array, but I’m getting lost of how to do that in my code:

    $kit_bin_count = 0;
    $kit_itemno_array = null;
    $kit_bin_array = null;

     // iterate through array
    while ($kit_row = odbc_fetch_array($result_ickitd)) {
      // store results from mysql in our own PHP array
      $kit_itemno_array[$kit_count] = $kit_row['COMPONENT'];
      // increment counter
      $kit_count++;
    }
    for($k=0;$k<sizeof($kit_itemno_array);$k++) {
        $var_kit_item = $kit_itemno_array[$k];
        $newvar_kit_item = trim($var_kit_item);
        }

/*  $params = "'".implode("','",$kit_itemno_array)."'";
    echo "$params"; */

/*  foreach ($kit_itemno_array as $country)
    {
        $query .= "OR stv.name = '{$country}', ";
    } */

    $sql_kit_bin="SELECT * FROM icitem, iciloc WHERE icitem.itemno = '$kit_itemno_array[$k]' AND iciloc.itemno = icitem.itemno";
    $result_kit_bin=odbc_exec($conn,$sql_kit_bin);
    while ($kit_bin_row = odbc_fetch_array($result_kit_bin)) {
        $kit_bin_array[$kit_bin_count] = $kit_bin_row['PICKINGSEQ'];
        $kit_bin_count++;
        print_r($kit_bin_array);
    }
    // END KITTING
        echo "<span style=\"color:#66CCFF\">";
        echo "$kit_bin_array[$k]";
        foreach ($kit_bin_array as $kit_bin) {
    //      if(strpos($file_array, $kit_item ) !== FALSE) {
            echo '<br />' . $kit_bin ; }
    //      else {
    //          $kit_post_array[] = $kit_item;
    //          echo '<br />' . 'KI: ' . $kit_item ; }
    //      }
    echo "</span>";

My code is returning the first value correctly and placing it in the $kit_item_array variable, but additional rows are getting lost. I’m unsure of how to loop this inside of my existing loop so everything is returned properly.

Here is a screenshot of the results, including a print_r() of the arrays being returned.

results

  • 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-28T02:31:37+00:00Added an answer on May 28, 2026 at 2:31 am

    If you indent your code properly, you will find it much easier to spot problems in your code. In your case, I suspect the problem lies in an extra } here:

    for($k=0;$k<sizeof($kit_itemno_array);$k++) {
        $var_kit_item = $kit_itemno_array[$k];
        $newvar_kit_item = trim($var_kit_item);
        } // <<--- This closes the loop when I don't think you meant to
    

    You code can be reduced down to one loop and a single query, I suspect (assuming you are using MySQL, as one of your comments suggests). I can;t give you the complete code because your first query is not shown, but lets for the purposes of this example say it is:

    SELECT COMPONENT FROM items
    

    If we make your second query, the one shown above, into:

    SELECT *
    FROM icitem t
    JOIN iciloc l ON l.itemno = t.itemno
    WHERE t.itemno IN (
      SELECT COMPONENT
      FROM items
    )
    

    …it pretty much renders all the code prior to that query pointless.

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

Sidebar

Related Questions

I have a bit of PHP code which I need to return an even
I have a bit of PHP code that grabs a list of files from
I have a bit of php code that I'm not understanding why it is
I have a bit of code that, using php, I want it to call
I have some problem convert C++ code to PHP. The purpose is I need
I have some PHP AJAX code that is supposed to validate some parameters sent
I have a bit of php code like this: $test = <!--my comment goes
its a little bit hard to understand. in the header.php i have this code:
I currently have a news website setup in PHP/MYSQL that's a bit old and
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:

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.