PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$sql= "SELECT user_company FROM users WHERE user_company LIKE '$letter%' ORDER BY user_company";
$productR = mysql_query($sql) or die (mysql_error());
This worked and showed the company alphabetically. Now however I have encrypted the database so now it is sorted by the encryption first letter rather than the decrypted text later. How can I add a function to the query or sort the $productR array using my decrypt($string) function?
I tried' order by decrypt(user_company)' but it threw an error.
You need to do a sort on the decrypted array of data: http://php.net/manual/en/function.sort.php. The MySQL ENCRYPT function is one way so there's no way for you to decrypt it. Instead you need to use DES_ENCRYPT and then you can use DES_DECRYPT to un-encrypt the data.
<?php
$sql= "SELECT DES_DECRPT(user_company) as user_company FROM users WHERE user_company LIKE '$letter%'";
$productR = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($productR); //here is your array of unencrypted user_company names
sort($row); //your array is re-sorted
print_r($row); //now print out all the data
?>
FUNCTION *database name*.decrypt does not exist
These functions are PHP functions.
If they are PHP functions, then you obviously cannot mix the two between eachother. Populate your array collection normally, apply your decrypt function (which you generally want to apply at the database level, and not PHP), then perform a sort() or usort() depending on your array structure.
Populate your array collection normally, apply your decrypt function (which you generally want to apply at the database level, and not PHP), then perform a sort() or usort()
I removed my last post because I assumed I didn't correctly understand your problem (realized after I had written the post) becuase your LIKE statement is based on the encrypted data. Thus, the returned dataset would not be correctly identified. This is exactly the reason why you want to implement this at the database level since you can selectively query the decrypted data and not have the overhead of having to query your entire dataset and filter in PHP.