Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare SQL Array to LDAP Array
    primarykey
    data
    text
    <p>I am trying to compare an array from an SQL query against an LDAP Search array. Do I need to change the format of the LDAP array (I believe it is multi-dimensional) to an associative array?</p> <p>What I am comparing, is a Payroll Table to Active Directory. This is to help with removing employees that no longer work for the company. Also, it will lead to a way to easily enter the employee number into A.D. as the Payroll table has all the employee numbers.</p> <p>My sql array appears like this:</p> <pre><code>[0] =&gt; Array ( [employeenumber] =&gt; 99999999999 [givenname] =&gt; JOHN [sn] =&gt; BOSS [mail] =&gt; [useraccountcontrol] =&gt; [displayname] =&gt;) &lt;--Each Entry appears like this </code></pre> <p>I added the last 3 columns/keys to the array as they do not exist in the sql database. I wanted to make them have the same keys as the LDAP array so that I can compare them.</p> <p>But my LDAP array is....way different. I don't even know where to start/stop with each portion of the array.</p> <p>It appears something like this:</p> <pre><code>[162] =&gt; Array ( [sn] =&gt; Array ( [count] =&gt; 1 [0] =&gt; Doe) [0] =&gt; sn [givenname] =&gt; Array ( [count] =&gt; 1 [0] =&gt; John) [1] =&gt; givenname [displayname] =&gt; Array ( [count] =&gt; 1 [0] =&gt; John Doe ) [2] =&gt; displayname [employeenumber] =&gt; Array ( [count] =&gt; 1 [0] =&gt; 99999 ) [3] =&gt; employeenumber [useraccountcontrol] =&gt; Array ( [count] =&gt; 1 [0] =&gt; 66048 ) [4] =&gt; useraccountcontrol [mail] =&gt; Array ( [count] =&gt; 1 [0] =&gt; john.doe@email.com ) [5] =&gt; mail [count] =&gt; 6 [dn] =&gt; CN=John Doe,CN=Users,DC=abc,DC=com ) </code></pre> <p>Do I need to make the LDAP array have the same format as the SQL array, and if so, how in the world do I do it? Also, not all entries from the LDAP array contain the part about employee number. Only a couple people have had their employee number entered, and if they do not have one in A.D. it just leaves that part out of the array I guess.</p> <p>Also what I want to do is create a table, that will compare these two arrays. I want it to list everyone from the SQL Array and everyone in the LDAP array (all sorted by last name because some SQL names have different first name, such as Mike where LDAP has Michael). I also want the row to highlight a certain color, if the person is in the LDAP Array but no relative match is in the SQL Array. I also need it to check to see if the employee number matches, and if it does, I only want it to show the entry from the LDAP array, and not the SQL Array entry.</p> <p>This way, with the way the table will display, if I find a person that had no employee number in A.D. I can enter it into A.D. and then the table would only display the A.D. entry for that person.</p> <p>Eventually I would like to modify the page so that you can actively change/add/delete people from Active Directory though this one page. But that is beyond the current scope of the project.</p> <p>If you need more information, please ask. I am not allowed to post all my current code as it is against company policy, but I can post portions that are general knowledge (things like how I am doing the LDAP search and stuff). I will just have to modify certain aspects to hide our information/table names/IP etc.</p> <p><strong>EDIT</strong></p> <p>I was able to figure it out with the help of a friend. I had to restructure my code and create a foreach loop in a foreach loop and use array push. </p> <p>In General I did the following:</p> <pre><code>foreach($LDAPARRAY as $value){ foreach($SQLARRAY as $key =&gt; $data){ if($data['employeenumber'] = $value['employeenumber']){ unset($SQLARRAY[$key]); } } } array_push($LDAPARRAY, $SQLARRAY); </code></pre> <p>I also did a similar process just against the LDAP array, to get it out of that stupid format that it is in. I did it to the LDAP array first, to normalize the array into an acceptable format (same format the SQL Array was already in). Then I was able to do the above code, to compare and combine the arrays. If the employee numbers match, I am only seeing the entries that come from the LDAP Array (as the SQL Array has its corresponding entry removed from the array).</p> <p>I can now print the new combined array to a table and see only entries that have an employee number(from sql table) and AD entries that have no employee number. I am still trying to figure out a field that I can use from the SQL table, that can match up to the AD entries, to find people who are in AD but not the SQL table. If you have any suggestions for that, that would be great.</p>
    singulars
    1. This table or related slice is empty.
    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