How to parse a list of lists in PHP,












0















I have this PHP+ HTML application that for each item in the item-list:



<input type="text" style="visibility: hidden" name="dataKey"  value=' . $single_product_info->unique_data_key . ' >
//some extra data here
<select class="SELECTCATEGORY" name="select_category_for_newProduct" multiple="multiple">';


so, when a button submit clicked, I will get a list of list from "SELECTCATEGORY",



in php function, I have as following



$datakey = $_POST['dataKey']; 
$category_id_pershop = $_POST['select_category_for_newProduct'];


I am trying to parse the list of data I received in the way that



foreach($datakey as $key => $value){
$data_key => $value,
$categoriys_per_item = $category_id_pershop[$key];
//here I try to access the list
}


the difficulty I have now is I can not parse the lists from the one list that I get from HTML input,



I am trying to solve the problem that I have a list of products, for each of them, has some attributes such as key, price and a list of categories,



when user click the submit button from HTML interface, I need PHP function to parse the data, I am not sure if my php idea could solve this problem.










share|improve this question





























    0















    I have this PHP+ HTML application that for each item in the item-list:



    <input type="text" style="visibility: hidden" name="dataKey"  value=' . $single_product_info->unique_data_key . ' >
    //some extra data here
    <select class="SELECTCATEGORY" name="select_category_for_newProduct" multiple="multiple">';


    so, when a button submit clicked, I will get a list of list from "SELECTCATEGORY",



    in php function, I have as following



    $datakey = $_POST['dataKey']; 
    $category_id_pershop = $_POST['select_category_for_newProduct'];


    I am trying to parse the list of data I received in the way that



    foreach($datakey as $key => $value){
    $data_key => $value,
    $categoriys_per_item = $category_id_pershop[$key];
    //here I try to access the list
    }


    the difficulty I have now is I can not parse the lists from the one list that I get from HTML input,



    I am trying to solve the problem that I have a list of products, for each of them, has some attributes such as key, price and a list of categories,



    when user click the submit button from HTML interface, I need PHP function to parse the data, I am not sure if my php idea could solve this problem.










    share|improve this question



























      0












      0








      0








      I have this PHP+ HTML application that for each item in the item-list:



      <input type="text" style="visibility: hidden" name="dataKey"  value=' . $single_product_info->unique_data_key . ' >
      //some extra data here
      <select class="SELECTCATEGORY" name="select_category_for_newProduct" multiple="multiple">';


      so, when a button submit clicked, I will get a list of list from "SELECTCATEGORY",



      in php function, I have as following



      $datakey = $_POST['dataKey']; 
      $category_id_pershop = $_POST['select_category_for_newProduct'];


      I am trying to parse the list of data I received in the way that



      foreach($datakey as $key => $value){
      $data_key => $value,
      $categoriys_per_item = $category_id_pershop[$key];
      //here I try to access the list
      }


      the difficulty I have now is I can not parse the lists from the one list that I get from HTML input,



      I am trying to solve the problem that I have a list of products, for each of them, has some attributes such as key, price and a list of categories,



      when user click the submit button from HTML interface, I need PHP function to parse the data, I am not sure if my php idea could solve this problem.










      share|improve this question
















      I have this PHP+ HTML application that for each item in the item-list:



      <input type="text" style="visibility: hidden" name="dataKey"  value=' . $single_product_info->unique_data_key . ' >
      //some extra data here
      <select class="SELECTCATEGORY" name="select_category_for_newProduct" multiple="multiple">';


      so, when a button submit clicked, I will get a list of list from "SELECTCATEGORY",



      in php function, I have as following



      $datakey = $_POST['dataKey']; 
      $category_id_pershop = $_POST['select_category_for_newProduct'];


      I am trying to parse the list of data I received in the way that



      foreach($datakey as $key => $value){
      $data_key => $value,
      $categoriys_per_item = $category_id_pershop[$key];
      //here I try to access the list
      }


      the difficulty I have now is I can not parse the lists from the one list that I get from HTML input,



      I am trying to solve the problem that I have a list of products, for each of them, has some attributes such as key, price and a list of categories,



      when user click the submit button from HTML interface, I need PHP function to parse the data, I am not sure if my php idea could solve this problem.







      php






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 14:35









      Jeff

      6,34911025




      6,34911025










      asked Nov 24 '18 at 14:26









      Levitt Shan HeLevitt Shan He

      184




      184
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You could "bind" your datakey to your categories.



          <select class="SELECTCATEGORY" name="select_category_for_newProduct[' . $single_product_info->unique_data_key . ']" multiple="multiple">';


          That way, when you iterate over the array you already have the datakey for the categories and other data you want to submit. Like below:



          $category_id_pershop = $_POST['select_category_for_newProduct'];

          foreach($category_id_pershop as $datakey => $categories){
          foreach ($categories as $categoryId) {
          // logic with the individual category
          }
          }


          I hope I could answered your question.






          share|improve this answer
























          • Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

            – Levitt Shan He
            Nov 24 '18 at 18:31











          • Or, is that possible to "bind" more than one variable to "category"?

            – Levitt Shan He
            Nov 24 '18 at 18:37











          • I used the index solve problem, thank you very much !!!

            – Levitt Shan He
            Nov 24 '18 at 18:54











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459150%2fhow-to-parse-a-list-of-lists-in-php%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You could "bind" your datakey to your categories.



          <select class="SELECTCATEGORY" name="select_category_for_newProduct[' . $single_product_info->unique_data_key . ']" multiple="multiple">';


          That way, when you iterate over the array you already have the datakey for the categories and other data you want to submit. Like below:



          $category_id_pershop = $_POST['select_category_for_newProduct'];

          foreach($category_id_pershop as $datakey => $categories){
          foreach ($categories as $categoryId) {
          // logic with the individual category
          }
          }


          I hope I could answered your question.






          share|improve this answer
























          • Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

            – Levitt Shan He
            Nov 24 '18 at 18:31











          • Or, is that possible to "bind" more than one variable to "category"?

            – Levitt Shan He
            Nov 24 '18 at 18:37











          • I used the index solve problem, thank you very much !!!

            – Levitt Shan He
            Nov 24 '18 at 18:54
















          0














          You could "bind" your datakey to your categories.



          <select class="SELECTCATEGORY" name="select_category_for_newProduct[' . $single_product_info->unique_data_key . ']" multiple="multiple">';


          That way, when you iterate over the array you already have the datakey for the categories and other data you want to submit. Like below:



          $category_id_pershop = $_POST['select_category_for_newProduct'];

          foreach($category_id_pershop as $datakey => $categories){
          foreach ($categories as $categoryId) {
          // logic with the individual category
          }
          }


          I hope I could answered your question.






          share|improve this answer
























          • Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

            – Levitt Shan He
            Nov 24 '18 at 18:31











          • Or, is that possible to "bind" more than one variable to "category"?

            – Levitt Shan He
            Nov 24 '18 at 18:37











          • I used the index solve problem, thank you very much !!!

            – Levitt Shan He
            Nov 24 '18 at 18:54














          0












          0








          0







          You could "bind" your datakey to your categories.



          <select class="SELECTCATEGORY" name="select_category_for_newProduct[' . $single_product_info->unique_data_key . ']" multiple="multiple">';


          That way, when you iterate over the array you already have the datakey for the categories and other data you want to submit. Like below:



          $category_id_pershop = $_POST['select_category_for_newProduct'];

          foreach($category_id_pershop as $datakey => $categories){
          foreach ($categories as $categoryId) {
          // logic with the individual category
          }
          }


          I hope I could answered your question.






          share|improve this answer













          You could "bind" your datakey to your categories.



          <select class="SELECTCATEGORY" name="select_category_for_newProduct[' . $single_product_info->unique_data_key . ']" multiple="multiple">';


          That way, when you iterate over the array you already have the datakey for the categories and other data you want to submit. Like below:



          $category_id_pershop = $_POST['select_category_for_newProduct'];

          foreach($category_id_pershop as $datakey => $categories){
          foreach ($categories as $categoryId) {
          // logic with the individual category
          }
          }


          I hope I could answered your question.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 16:50









          Pedro JannottiPedro Jannotti

          714




          714













          • Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

            – Levitt Shan He
            Nov 24 '18 at 18:31











          • Or, is that possible to "bind" more than one variable to "category"?

            – Levitt Shan He
            Nov 24 '18 at 18:37











          • I used the index solve problem, thank you very much !!!

            – Levitt Shan He
            Nov 24 '18 at 18:54



















          • Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

            – Levitt Shan He
            Nov 24 '18 at 18:31











          • Or, is that possible to "bind" more than one variable to "category"?

            – Levitt Shan He
            Nov 24 '18 at 18:37











          • I used the index solve problem, thank you very much !!!

            – Levitt Shan He
            Nov 24 '18 at 18:54

















          Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

          – Levitt Shan He
          Nov 24 '18 at 18:31





          Hi, thank you a lot, it helps!!! however I lost the access to another variable such as "$platform = $_POST['platform']; $shop = $_POST['shop_name']; ", and more, I used to access them in the for-loop in my initial question, in a way like "$shopinfo = $shop[$key];, $platform_info= $platform[$key], and for $data_key itself I use the $value ", But now with the new for-loop you provided, I tried this " $shopinfo = $shop[$datakey]; " and get empty value back, could me help me further? I appreciate

          – Levitt Shan He
          Nov 24 '18 at 18:31













          Or, is that possible to "bind" more than one variable to "category"?

          – Levitt Shan He
          Nov 24 '18 at 18:37





          Or, is that possible to "bind" more than one variable to "category"?

          – Levitt Shan He
          Nov 24 '18 at 18:37













          I used the index solve problem, thank you very much !!!

          – Levitt Shan He
          Nov 24 '18 at 18:54





          I used the index solve problem, thank you very much !!!

          – Levitt Shan He
          Nov 24 '18 at 18:54




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459150%2fhow-to-parse-a-list-of-lists-in-php%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Tonle Sap (See)

          I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

          Guatemaltekische Davis-Cup-Mannschaft