LDAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesLDAP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 30th, 2003, 02:19 PM
rmace rmace is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 rmace User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Formatting query results/table

I have seen this posted in the MySQL forums but am new to LDAP/PHP stuff. I want to post data from an LDAP query into a table format for an online phone directory. The results returned are a name and a phone number that is formatted right now as a table with two rows. Like the following:

User1 Number1
User2 Number2
User3 Number3
User4 Number4

I want it to read:
User1 Number1 User2 Number2
User3 Number3 User4 Number4

Any help or suggestions is greatly appreciated. The full code is as follows:

PHP Code:
<?php

error_reporting 
(7);

    
$surname trim($_REQUEST['sursearch']);
  
$ds ldap_connect("10.1.2.1");  // must be a valid LDAP server!

 
if ($ds) { 
     
$r ldap_bind($ds);     // this is an "anonymous" bind, typically read only access

// Search surname entry
    
$sr ldap_search($ds"o=bl""sn=$surname*");
      
$info ldap_get_entries($ds$sr);

     for (
$i=0$i<$info["count"]; $i++) {
//This line looks to see if telephonenumber field actually has a number if not it does not post the data
      
if ($info[$i]["telephonenumber"][0]) {
      if (
$info[$i]["fullname"][0])
    
//Put results in a table
    
echo "    <table border='1' cellspacing='1' cellpadding='0'>
            <td valign='center' align='left' bgcolor='#ffffff' width=200><font size='3'>" 
$info[$i]["fullname"][0] . "</td></font>
            <td valign='center' align='center' bgcolor='#ffffff' width=100><font size='3'>" 
$info[$i]["telephonenumber"][0] . "</td></font>
            "
;
        }
      }
  }
      echo 
"</table>";
     
ldap_close($ds);
?>

Last edited by Viper_SB : July 30th, 2003 at 03:36 PM.

Reply With Quote
  #2  
Old August 4th, 2003, 01:21 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,845 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 20 h 16 m 56 sec
Reputation Power: 634
Try this out let me know if you ned more help

PHP Code:
//    error_reporting (7);
    
$surname trim($_REQUEST['sursearch']);
    
$ds ldap_connect("10.1.2.1");  // must be a valid LDAP server!

if ($ds) { 
    
$r ldap_bind($ds);    // this is an "anonymous" bind, typically read only access
    // Search surname entry
    
$sr ldap_search($ds"o=bl""sn=$surname*");
    
$info ldap_get_entries($ds$sr);

### create table first before looping though the results ###
    
echo "<table border='1' cellspacing='1' cellpadding='0'>";
    echo 
'<tr>'### table rows ###
    
for ($i=0$i<$info["count"]; $i++) {
        if (
$i 2) { ### this adds table rows ###
            
echo '</tr>';
            echo 
'<tr>';
        }
        
//This line looks to see if telephonenumber field actually has a number if not it does not post the data
        
if ($info[$i]["telephonenumber"][0]) {
            if (
$info[$i]["fullname"][0])
                
//Put results in a table
                
echo "<td valign='center' align='left' bgcolor='#ffffff' width=200><font size='3'>" $info[$i]["fullname"][0] . "</td></font>
                <td valign='center' align='center' bgcolor='#ffffff' width=100><font size='3'>" 
$info[$i]["telephonenumber"][0] . "</td></font>
                "
;
        }
    }
}
echo 
'</tr>'### table rows ###
echo "</table>";
ldap_close($ds); 

Reply With Quote
  #3  
Old August 4th, 2003, 01:51 PM
rmace rmace is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 2 rmace User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's almost got it! It does return all the results, doesn't skip anything, formats it in two columns but the second column contains blank entries. Looks to be something that hopefully I can figure out. I think I see the issue already. I have entries in eDirectory that do not have a fullname or telephonenumber entry and it skips over them but leaves a blank field in their place.

I will post the fully functional code here as soon as I have it.

Many thanks for putting me on the right track Viper!

Reply With Quote
  #4  
Old August 4th, 2003, 04:59 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,845 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 20 h 16 m 56 sec
Reputation Power: 634
Sure np

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesLDAP Programming > Formatting query results/table

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap