imperium2335 Posted April 30, 2011 Share Posted April 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/235212-sorting-complex-array/ Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235212-sorting-complex-array/#findComment-1208754 Share on other sites More sharing options...
imperium2335 Posted April 30, 2011 Author Share Posted April 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235212-sorting-complex-array/#findComment-1208756 Share on other sites More sharing options...
imperium2335 Posted April 30, 2011 Author Share Posted April 30, 2011 Any ideas on if this is possible or not? Quote Link to comment https://forums.phpfreaks.com/topic/235212-sorting-complex-array/#findComment-1208802 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.