|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Compare php array results
I have been working for last few days to get an AuthLDAP mod to auto-create a Postnuke Group and make user member based on a LDAP DN ("ou" for department in eDirectory). Anyway I got the mod creating the group based on the department of the user. The problem is that if another user logs in from the same department of another user, the pnGroup is duplicated. So I write the following code to check the 'name' of the existing pnGroups and to not create it if it exists...but it is still not working. I tried playing with arrays but still no go. I should probably mention that I am just above a beginner in PHP. Here is the code:
Code:if ($result->EOF) { $sql2 = "SELECT $groupscolumn[name] FROM $groupstable"; $result2 = $dbconn->Execute($sql2); $myrow = mysql_fetch_array($result2); $grpmem = pnVarPrepForStore($info[0]["ou"][0]); if ($myrow != $grpmem) { $query3 = "INSERT INTO $groupstable ( $groupscolumn[name]) VALUES('".pnVarPrepForStore($info[0]["ou"][0])."' )"; $dbconn->Execute($query3); $gid = $dbconn->PO_Insert_ID($groupstable,$groupscolumn['gid']); } else { } It is still duplicating the groups though. I try to echo $myrow and I either get nothing, 'Object', or 'Array'. If I echo $grpmem I get the correct department. I have been looking at this same piece of code for the last 6 hours and my eyes are beginning to bleed. Can anyone shed some light on this for me? Why is the results of $myrow not returning the correct results. Is there a syntax error in the code above? |
|
#2
|
|||
|
|||
|
Actually, I kinda figured it out by using 'in_array'. Still have one problem though....suppose:
$groups[] = array('name' => $name); resulted Code:
Array([0]=>([name]=>Users)[1]=>Array([name]=>Admins)[2]=>Array([name]=> WPC And if $LDAPgrp = pnVarPrepForStore($info[0]["ou"][0]); resulted Code:
WPC Why doesn't the below line update the said table? Code:
if (!in_array($LDAPgrp,$groups)) {
$query = "INSERT INTO $groupstable
( $groupscolumn[name])
VALUES('".pnVarPrepForStore($info[0]["ou"][0])."'
)";
$dbconn->Execute($query);
$gid = $dbconn->PO_Insert_ID($groupstable,$groupscolumn['gid']);
}else{
return FALSE;
}
Is there something special I need to do to check the values of the array....Users,Admins,WPC? Last edited by vanshan : February 14th, 2005 at 01:35 PM. Reason: oops - need to finish |
|
#3
|
|||
|
|||
|
Quote:
Bum -PITY - Bump |
|
#4
|
||||
|
||||
|
Try outputting your query before you execute it...
Are you getting an error? Perhaps a variable isn't being set... |
|
#5
|
||||
|
||||
|
As for comparing PHP arrays, PHP has some built in functions that might help you
Look into array_udiff() This might not be the best solution for your problem; just thought I'd point it out. |
|
#6
|
|||
|
|||
|
Quote:
The problem was that the query out-putted the result as a multi-array. I changed $groups[] = array('name' => $name) to $groups[] = $name and the in_array is now working. I need to now figure out how to search a multi-array and all should be good. I try using in_array_multi as outlined on php.net but it keeps erroring out. I am running php v4.3.10 which I thought supported this multi function but obviously not. I post if/when I get it figured out. Thanks for your help. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Compare php array results |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|