PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 12th, 2005, 10:50 AM
vanshan vanshan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 vanshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 8 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old February 14th, 2005, 01:20 PM
vanshan vanshan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 vanshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 8 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old February 16th, 2005, 08:48 AM
vanshan vanshan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 vanshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by vanshan
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?


Bum -PITY - Bump

Reply With Quote
  #4  
Old February 17th, 2005, 07:54 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Try outputting your query before you execute it...
Are you getting an error?
Perhaps a variable isn't being set...

Reply With Quote
  #5  
Old February 17th, 2005, 08:01 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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.

Reply With Quote
  #6  
Old February 17th, 2005, 11:47 AM
vanshan vanshan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 4 vanshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 8 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
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.


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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Compare php array results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway