Note that there are some explanatory texts on larger screens.

plurals
  1. POMultidimensional arrays to insert for one row
    primarykey
    data
    text
    <p>I have three arrays that look like this:</p> <p><strong>ingredientQTY</strong> is the first input box in each row, <strong>measurements</strong> is the select/dropdown in each row, and <strong>ingredientsNAME</strong> is the last input box in each row. As you can see, there can be infinite numbers of <strong>ingredientQTY's, ingredientNAME's, and measurements</strong>. </p> <p><img src="https://i.stack.imgur.com/79pQ6.png" alt="picture"></p> <p>When I send them to my php script, the data is in arrays like:</p> <pre class="lang-none prettyprint-override"><code>IngredientQTY ( [0] =&gt; 5 //The first row [1] =&gt; 5 //The next rows value ) Measurements ( [0] =&gt; Bunch //The first row [1] =&gt; Bunch //The next rows value ) IngredientName ( [0] =&gt; 5 //The first row [1] =&gt; 5 //The next rows value ) </code></pre> <p>I'm trying to upload them to a table called ingredients that has 3 columns: <code>ingredientNAME</code>, <code>ingredientQTY</code>, and <code>measurements</code>. </p> <p>In my php script, I'm combining them into a multidimensional array, which is assigned to <code>$ingredientsROW</code>:</p> <pre class="lang-php prettyprint-override"><code>foreach($_POST as $key =&gt; $value) { $value = $this-&gt;input-&gt;post($key); $ingredientQTY = $this-&gt;input-&gt;post('ingredientQTY'); $measurements = $this-&gt;input-&gt;post('measurements'); $ingredientNAME = $this-&gt;input-&gt;post('ingredientNAME'); $ingredientsROW[] = array($ingredientQTY, $measurements, $ingredientNAME); break; } </code></pre> <p>My question is: How can I get group all the first row of form elements (which means the first <code>ingredientQTY</code>, the first <code>measurements</code> dropdown and the first <code>ingredientNAME</code> and insert them into a row?</p> <p>The only way I could think of is to have one insert where I insert <code>ingredientQTY</code>, then look up the id of the row I just inserted and use two mysql updates to enter for the same row, but I'm pretty sure there is more efficient ways of going about this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload