Jump to content

PHP Arrays Help!


Xusen

Recommended Posts

Hi Guys
i am having a problem with data in an array that i need to convert, anyways here is code

[code]<?php
$ldapserver=ldap_connect("xxx.xxx.xxx"); 

if($_POST['stype'] == 1)

{
$dn = "o=any";
$filter = "givenname=" . trim($_POST['infom']);
}
else if($_POST['stype'] == 2)

{
$dn = "o=any";
$filter = "sn=" . trim($_POST['infom']);
}
else if($_POST['stype'] == 3)

{
$dn = "o=any";
$filter = "cn=" . trim($_POST['infom']);
}



$justthese = array("cn", "sn", "givenname", "accountbalance");

$sr=ldap_search($ldapserver, $dn, $filter, $justthese);

$info = ldap_get_entries($ldapserver, $sr);

if($info["count"] == 0)
{
print "<p>No Records found, please double check your search parameters and try again";
print "<br>"."<br>"."<br>";
print "<a href=../search.html >Click Here to search again.</a>";
}
else
{

print "<table border=2><tr>"
. "<th>Number"
. "<th>Name"
. "<th>Balance";
for($i=0;$i<$info["count"];$i++)
{
$row[$i] = "<tr>"
. "<td>" . $info[$i]["cn"][0]
. "<td>" . $info[$i]["givenname"][0] . "  " .  $info[$i]["sn"][0]
. "<td>" ."£". $info[$i]["accountbalance"][0];
}
sort($row);
for($i=0;$i<$info["count"];$i++) print $row[$i] . "\n";
print "</table>";
}

?>[/code]

the script above is for searching an ldap server to get the name and print credit of the user , problem is that the field accountbalance is stored in the server as string and in pence , i need to convert it to pounds and pence, so basically devide it by 100 to get the right result. here is a typical output from the above script

Number Name  Balance
XM      Xusen  £994975 

the user has only £9949.75 which is the above number devided by 100, so how do i get it to print devided answer?, any help will be appriciated and thanks in advance.
Link to comment
Share on other sites

Hi

thanks for the reply :)

the £ sign is not in the database, its added on by might script, its not possible to change that, there are over 3000 records with this data and its dynamicly changed everytime a user prints something, so i am guessing it has to be this way. the only choice i have as the script writer will be to find a way to convert the data to integer and devide by 100. anymore suggestions keep them coming.

Thanks
Link to comment
Share on other sites

Hi Ken
Thanks for the reply,

the number will always change and is delivered to the array as a string for each user who is found.

the way my program works is like this.

user opens search page (html) and enters the name or id of user and clicks search, my scripts recieves this and connects to the server and prints the result of the search ie. print credit etc etc. the data is put into the array and is printed one after another, i want to be able to devide it by 100 when the loop starts for each returned result.

so if it finds three users with the specified surname it prints the following
                                             
                                                i want
                                                  i
                                                  I
                                                  V
Name          ID    Credit(original)  Credit /100
James Hunt  1    10000              100
James Bond  2    15896              158.96
James Task  3    1847                18.47

thanks in advance and any help would be appriciated.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.