Jump to content

Recommended Posts

Hi,

 

I have got some data out of my database, I would now like to sort all of this by putting the data into arrays, something looking like this:

 

branch - costs - profit

 

France - 406.85 - 1392.48

 

So each branch is one item in the array, but has the costs and profit with it too.

 

I would then like to sort those arrays by things like branch name, costs and profit.

 

Is this possible?

Link to comment
https://forums.phpfreaks.com/topic/235212-sorting-complex-array/
Share on other sites

I would then like to sort those arrays by things like branch name, costs and profit.

Wouldn't it be easier to do this within your query eg

SELECT brand, costs, profit FROM table ORDER BY brand ASC

That will return all the branches in alphabetical order.

I don't think so, my query is already really complicated, plus there is two of them, one retrieves the costs, and the other retrieved the profit/margin:

 

$currentMonth = 4;date('n') ;
$currentYear = 2011;date('Y') ;

$branchResults = mysql_query("SELECT branch,
       sum(if(currency = '£',absoluteTotal,0)) AS branchpound,
       sum(if(currency = '$',absoluteTotal,0)) AS branchdollar,
       sum(if(currency = '€',absoluteTotal,0)) AS brancheuro
  FROM invoices_out
  WHERE MONTH(invoiceDate) = '$currentMonth'
  AND YEAR(invoiceDate) = '$currentYear'
  GROUP BY branch") or die(mysql_error());

 

And for costs:

$branchCostResult = mysql_query("SELECT enquiries.assignedToT, users.branch,
       sum(if(pourbaskets.currency = '£',total,0))+sum(if(pourbaskets.currency = '£',shippingTotal,0)) AS branchpound,
       sum(if(pourbaskets.currency = '$',total,0))+sum(if(pourbaskets.currency = '$',shippingTotal,0)) AS branchdollar,
       sum(if(pourbaskets.currency = '€',total,0))+sum(if(pourbaskets.currency = '€',shippingTotal,0)) AS brancheuro
  FROM pourbaskets, enquiries, users, jobs
  WHERE pourbaskets.enquiryRef = enquiries.id
  AND jobs.trader = users.userName
  AND jobs.enquiryRef = enquiries.id
  AND jobs.isInvoiced = 1
  AND users.branch = '$currentBranch'
  AND MONTH(dateInvoiced) = '$currentMonth'
  AND YEAR(dateInvoiced) = '$currentYear'
  GROUP BY users.branch") or die(mysql_error());

 

outputs me rows like "France £22,016.84 £10,729.72" which is great, but I want to sort them some how.

 

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.