Xusen Posted November 29, 2006 Share Posted November 29, 2006 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 scriptNumber 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. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 29, 2006 Share Posted November 29, 2006 remove the £ from your database and leave it as an integer OR change it to a decimal data type and you can store it as 9949.75 then!!!!use number_format(); to format the output of your scripts Quote Link to comment Share on other sites More sharing options...
Xusen Posted November 29, 2006 Author Share Posted November 29, 2006 Hithanks 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 Quote Link to comment Share on other sites More sharing options...
Xusen Posted December 1, 2006 Author Share Posted December 1, 2006 *bump ;) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 Did you try just dividing by 100 an printing the result? PHP will treat a string as a number automatically if the string is numeric.[code]<?php$accountbalance = "994975";echo '£' . number_format(($accountbalance/100),2);?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Xusen Posted December 1, 2006 Author Share Posted December 1, 2006 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 VName ID Credit(original) Credit /100James Hunt 1 10000 100James Bond 2 15896 158.96James Task 3 1847 18.47thanks in advance and any help would be appriciated. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 Please post the script that prints the table.Ken Quote Link to comment Share on other sites More sharing options...
Xusen Posted December 4, 2006 Author Share Posted December 4, 2006 Hi Kenthe one in my first post does this, the only thing i havent posted is just the html page which provides the input, it option 1,2,3 and the input box.regardshussein Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.