Note that there are some explanatory texts on larger screens.

plurals
  1. POArray, need to sort via Keys
    primarykey
    data
    text
    <p>Ok, not really sure how to do this. I have values that are being outputted from a SQL query like so:</p> <pre><code>$row[0] = array('lid' =&gt; 1, 'llayout' =&gt; 1, 'lposition' =&gt; 1, 'mid' =&gt; 1, 'mlayout' =&gt; 1, 'mposition' =&gt; 0); $row[1] = array('lid' =&gt; 2, 'llayout' =&gt; 1, 'lposition' =&gt; 0, 'mid' =&gt; 2, 'mlayout' =&gt; 1, 'mposition' =&gt; 0); $row[2] = array('lid' =&gt; 2, 'llayout' =&gt; 1, 'lposition' =&gt; 0, 'mid' =&gt; 3, 'mlayout' =&gt; 1, 'mposition' =&gt; 1); $row[3] = array('lid' =&gt; 3, 'llayout' =&gt; 1, 'lposition' =&gt; 1, 'mid' =&gt; 4, 'mlayout' =&gt; 1, 'mposition' =&gt; 1); $row[4] = array('lid' =&gt; 4, 'llayout' =&gt; 1, 'lposition' =&gt; 2, 'mid' =&gt; 5, 'mlayout' =&gt; 1, 'mposition' =&gt; 0); </code></pre> <p>etc. etc.</p> <p>Ok, so the best thing I can think of for this is to give lid and mid array keys and have it equal the mposition into an array within the while loop of query like so...</p> <pre><code>$old[$row['lid']][$row['mid']] = $mposition; </code></pre> <p>Now if I do this, I need to compare this array's keys with another array that I'll need to build based on a $_POST array[].</p> <pre><code>$new = array(); foreach($_POST as $id =&gt; $data) { // $id = column, but we still need to get each rows position... $id = str_replace('col_', '', $id); // now get the inner array... foreach($data as $pos =&gt; $idpos) $new[$id][$idpos] = $pos; } </code></pre> <p>Ok, so now I have 2 arrays of info, 1 from the database ($old), and another from the $_POST positions ($new), I hope I got the array keys correct.</p> <p>Now I need to figure out which one's changed, comparing from the old to the new. And also, need to update the database with all of the new positions where new lid = the old lid, and the new mid = the old mid from each array. I'm sure I'll have to use array_key or array_key_intersect somehow, but not sure exactly how...??? </p> <p>Also, I don't think an UPDATE would be useful in a foreach loop, perhaps there's a way to do a CASE statement in the UPDATE query?</p> <p>Also, Am I going about this the right way? OR should I do it another way instead of using a muli-dimensional array for this.</p> <p>Basically I need to update in the database where each array within the same keys = changed value and I need to update it where mid = mid in the database (the second key value).</p> <p>Also, I think it would kinda be like this:</p> <pre><code>$newest = array(); foreach($old as $c =&gt; $d) { foreach($d as $e =&gt; $f) $newest[$c][$e] = $new[$c][$e]; } </code></pre> <p>But isn't there a better way to do this with 1 or 2 php array functions? And I still also need to know which values have changed.... arggg</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.
    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