I’ve a little PHP script that get results from my database. In the mysql_fetch_array() I count files on the server in a folder. I get the folder name of the MySQL results.
What I want is to build a list with all companynames and a total of all the files from the associated folder.
Well, so far so good. But the problem is I want to sort the list on the total of files.
My script look like this:
<? $query = "SELECT * FROM users WHERE id = '".$_COOKIE['users_id']."'"; $sql = mysql_query("$query");
while ($fill = mysql_fetch_array($sql)) {
$multi_user = $fill['multi_user'];
$folder = $fill['folder'];
$company_name = $fill['company_name'];
$directory_purchase = '/var/www/vhosts/domain.nl/private/'.$folder.'/purchase/';
$directory_sales = '/var/www/vhosts/domain.nl/private/'.$folder.'/sales/';
$email_folder = '/var/www/vhosts/domain.nl/private/'.$folder.'/email/';
$kas_folder = '/var/www/vhosts/domain.nl/private/'.$folder.'/bank/';
$multi_folder = '/var/www/vhosts/domain.nl/private/'.$folder.'/multi/';
$total_purchase = count(glob($directory_purchase."*.*"));
$total_sales = count(glob($directory_sales."*.*"));
$total_email = count(glob($email_folder."*.*"));
$total_kas = count(glob($kas_folder."*.*"));
$total_multi = count(glob($multi_folder."*.*"));
$total = $total_purchase + $total_sales + $total_email + $total_kas + $total_multi;
echo '<table>
<tr>
<td>'. $company_name. '</td>
<td>'. $total .'</td>
</tr>
</table>';
}?>
Somebody know how to do this?
Well…just create an array and fill it during the loop. Then sort the array and loop again. Additionally you need to cache the company names:
Obviously you also could put all information into one single array and use
usort(), but in my opionion that’s a little overkill.