What you are looking for is the right LDAP filter to use to retrieve all users. This depends on what the entries look like - try to figure out what they have in common. For now, I suppose that all users have a mail attribute and share the objectClass organizationalPerson. In that case, retrieve all the entries like this:
$result = ldap_search($ldapconn,$ldaptree, "(&(mail=*)(objectClass=organizationalPerson))") or die ("Error in search query: ".ldap_error($ldapconn));
Then go ahead, either as you tried in your example, or using the ldap_next_entry
method.