Jump to content

gdeliana

Members
  • Posts

    22
  • Joined

  • Last visited

gdeliana's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ok, let's say i want from the sorted multidimensional array to output the third value of each array. I did like this as suggested by Muddy_Funster for($counter = 0; $counter <= count($rArray)-1; $counter++){ foreach($rArray[$counter] as $key => $value){ echo "$key = $value <br />"; } echo "<hr/>"; } just a lil bit modified but works the same. It outputs every value. My problem now is since i got the results sorted by the first value, i cannot change it now (unless i sort by second value, but i don't know how to do that) and in the output i want the third value to be outputted first.
  2. Thanks a lot!!! I am just a beginner, i have 3 weeks that have started programming at all . The last thing that i wanted to ask is: Can i use these results as php variables again?
  3. It's working actually , THANKS A LOT!!!!!!! I just had the indexes of the sub arrays assigned as values also, which i had to rename only . Now i will echo the results, let's see
  4. This is the result: arsort($rArray, SORT_DESC); var_dump($rArray); [b]array[/b] [i](size=13)[/i] 10 => [b]array[/b] [i](size=6)[/i] 95746 => float 95746.118300622 6279 => float 6279.5408451346 1002932 => float 1002932.0669677 18677 => float 18677.945713529 12682 => float 12682.417945625 13854 => float 13854.450434711 9 => [b]array[/b] [i](size=6)[/i] 95746 => float 95746.118300622 6279 => float 6279.5408451346 1002932 => float 1002932.0669677 18677 => float 18677.945713529 12682 => float 12682.417945625 13854 => float 13854.450434711 11 => [b]array[/b] [i](size=6)[/i] 95746 => float 95746.118300622 6279 => float 6279.5408451346 1002932 => float 1002932.0669677 18677 => float 18677.945713529 12682 => float 12682.417945625 13854 => float 13854.450434711 12 => [b]array[/b] [i](size=6)[/i] 47967 => float 47967.660887516 6611 => float 6611.3356882811 1002419 => float 1002419.5001146 9210 => float 9210.0558512346 11268 => float 11268.25030132 12896 => float 12896.497848447 13 => [b]array[/b] [i](size=6)[/i] 48040 => float 48040.653648759 6610 => float 6610.8287941058 1002342 => float 1002342.6441463 9209 => float 9209.3497119785 11268 => float 11268.25030132 12896 => float 12896.497848447 8 => [b]array[/b] [i](size=6)[/i] 98481 => float 98481.424684471 6260 => float 6260.5456619134 999898 => float 999898.26579654 18621 => float 18621.446200304 9511 => float 9511.8134592191 13854 => float 13854.450434711 7 => [b]array[/b] [i](size=6)[/i] 95548 => float 95548.769055707 6280 => float 6280.911326002 1003150 => float 1003150.9522721 18682 => float 18682.022089155 12682 => float 12682.417945625 13854 => float 13854.450434711 3 => [b]array[/b] [i](size=6)[/i] 105748 => float 105748.35846424 6210 => float 6210.0808439984 1002257 => float 1002257.2803817 20586 => float 20586.115871946 12984 => float 12984.067051625 14053 => float 14053.750153676 2 => [b]array[/b] [i](size=6)[/i] 105748 => float 105748.35846424 6210 => float 6210.0808439984 1002257 => float 1002257.2803817 20586 => float 20586.115871946 12984 => float 12984.067051625 14053 => float 14053.750153676 4 => [b]array[/b] [i](size=6)[/i] 105748 => float 105748.35846424 6210 => float 6210.0808439984 1002257 => float 1002257.2803817 20586 => float 20586.115871946 12984 => float 12984.067051625 14053 => float 14053.750153676 5 => [b]array[/b] [i](size=6)[/i] 95622 => float 95622.77502255 6280 => float 6280.3973956767 1003068 => float 1003068.8702829 18680 => float 18680.493448295 12682 => float 12682.417945625 13854 => float 13854.450434711 6 => [b]array[/b] [i](size=6)[/i] 95622 => float 95622.77502255 6280 => float 6280.3973956767 1003068 => float 1003068.8702829 18680 => float 18680.493448295 12682 => float 12682.417945625 13854 => float 13854.450434711 1 => [b]array[/b] [i](size=6)[/i] 105748 => float 105748.35846424 6210 => float 6210.0808439984 1002257 => float 1002257.2803817 20586 => float 20586.115871946 12984 => float 12984.067051625 14053 => float 14053.750153676 I don't understand by which criteria they got sorted, but they are not sorted by their first value. I also used the rsort() but it simply reindexes them and the results stay the same.
  5. Well, i'm also wondering the same . It shouldn't be so difficult. I found also this in stackoverflow:http://stackoverflow.com/questions/2699086/sort-multidimensional-array-by-value-2, I think that we should specify the criteria of sorting.
  6. I think it's not so difficult if the arrays keep their structure. I just need to sort their order by the first number you see in them. So the array that has the first value higher should be in the first place. If i use your code $rArray is my entire multidimensional array, but i should specify it that i need the SUB arrays sorted by their first value. I used your code but they are not sorted from the highest to the smallest arsort($rArray, SORT_DESC); and if i do it like this: arsort($rArray[$num][$profit], SORT_DESC); i get this error: Warning: arsort() expects parameter 1 to be array, double given in C:\wamp\www\calc\calc1 - Copy.php on line 222
  7. Ok i did it, however i need to sort the arrays, but not the values inside them. Here is the output: [b]array[/b] [i](size=13)[/i] 1 => [b]array[/b] [i](size=6)[/i] 54954 => float 54954.74347101 13125 => float 13125.628562903 1000374 => float 1000374.6160332 10097 => float 10097.841093294 11394 => float 11394.765048752 12575 => float 12575.18524806 2 => [b]array[/b] [i](size=6)[/i] 54954 => float 54954.74347101 13125 => float 13125.628562903 1000374 => float 1000374.6160332 10097 => float 10097.841093294 11394 => float 11394.765048752 12575 => float 12575.18524806 3 => [b]array[/b] [i](size=6)[/i] 54954 => float 54954.74347101 13125 => float 13125.628562903 1000374 => float 1000374.6160332 10097 => float 10097.841093294 11394 => float 11394.765048752 12575 => float 12575.18524806 4 => [b]array[/b] [i](size=6)[/i] 54954 => float 54954.74347101 13125 => float 13125.628562903 1000374 => float 1000374.6160332 10097 => float 10097.841093294 11394 => float 11394.765048752 12575 => float 12575.18524806 5 => [b]array[/b] [i](size=6)[/i] 49710 => float 49710.953291902 13198 => float 13198.458982057 1000734 => float 1000734.5436461 9178 => float 9178.6376459356 11261 => float 11261.62419264 12521 => float 12521.708395092 6 => [b]array[/b] [i](size=6)[/i] 49710 => float 49710.953291902 13198 => float 13198.458982057 1000734 => float 1000734.5436461 9178 => float 9178.6376459356 11261 => float 11261.62419264 12521 => float 12521.708395092 7 => [b]array[/b] [i](size=6)[/i] 49674 => float 49674.293645881 13198 => float 13198.968143807 1000773 => float 1000773.1493464 9178 => float 9178.991733577 11261 => float 11261.62419264 12521 => float 12521.708395092 8 => [b]array[/b] [i](size=6)[/i] 52384 => float 52384.439029542 13161 => float 13161.327235701 997919 => float 997919.13759795 9152 => float 9152.8150218379 8446 => float 8446.21814448 12521 => float 12521.708395092 9 => [b]array[/b] [i](size=6)[/i] 49772 => float 49772.052701936 13197 => float 13197.61037914 1000670 => float 1000670.2008123 9178 => float 9178.047499867 11261 => float 11261.62419264 12521 => float 12521.708395092 10 => [b]array[/b] [i](size=6)[/i] 49772 => float 49772.052701936 13197 => float 13197.61037914 1000670 => float 1000670.2008123 9178 => float 9178.047499867 11261 => float 11261.62419264 12521 => float 12521.708395092 11 => [b]array[/b] [i](size=6)[/i] 49772 => float 49772.052701936 13197 => float 13197.61037914 1000670 => float 1000670.2008123 9178 => float 9178.047499867 11261 => float 11261.62419264 12521 => float 12521.708395092 12 => [b]array[/b] [i](size=6)[/i] 25214 => float 25214.225740612 13538 => float 13538.691309158 1000320 => float 1000320.7701461 4575 => float 4575.8889235416 10615 => float 10615.20150601 12257 => float 12257.908486479 13 => [b]array[/b] [i](size=6)[/i] 25250 => float 25250.555281567 13538 => float 13538.1867322 1000283 => float 1000283.4889348 4575 => float 4575.7183835641 10615 => float 10615.20150601 12257 => float 12257.908486479 I need to sort them by the first value, but maintain the structure inside them. So the first array to be the one which has the first value highest. I know there are a lot of sorting functions but i can't get the right one for this. Thanks for your help!!!
  8. Ok, i tried it, but when i echo the results: echo "$rArray[$i][$row['filedName6']]"; i get only the result for that loop, i think the values are not pushed. Also noticed that you use the "mysql_fetch_assoc" and i use "mysql_fetch_array".
  9. Thanks, i will try it. Is this a multidimensional array? And the name of the array is rArray?
  10. If someone could tell me how to create such an array like a matrix. I know all the types of arrays (saw them in w3schools) but it seems that they just put the variables one after another and index them, one cannot know where a loop starts and ends.
  11. Thanks for the reply . It's basically a financial claculator for savings. I have a list of saving companies in mysql which have their own account limitations. The calculations are done based in user form input and limited by the variables of mysql query. The output consists of divs where each div represents one saving company and for it i calculate the saving amount, tax, and the PROFIT. I have done all of this and the results output according to $row['interest_rate'], but i want them ordered by the later generated variable which is the $profit. I have already posted here my code before but as it was a bit long nobody wanted to look at it . A loop creates 6 php variable. So i want an array which will have in each row a loop with these 6 variables so 6 columns. It will look like a matrix.
  12. Hello!!!! I have a while loop which outputs variables made from mysql query, but i want to order this output according to one of those php variables created later after the mysql query. I think that i can put all the outputted variables of the loop in an array and than order them in the array and output them. How can i make an array that will look like a matrix where nr.rows=nr.loops and nr.columns=nr.variables THAN order these rows by one column....like in excel: you create a table and than you sort them according to a column . After i output the array with a "for" loop for each row . PLS HEEELP. I know what i want but i don't know how can it be done EDIT: If your answers will be you can do it in mysql query.....than i say simply it's impossible......because the variable which i want to order the results from is generated AFTER the query and it's a mix of mysql variables($row[''])+form input variables ($_POST['']). So simply i cannot do it in mysql unless you suggest s.m.th else
  13. Ok guys, sorry for my late reply but i needed to translate the code variable names in english and make it a bit more clean . Here you have it: <form method="post" action="calc2.php" /> <input name="target" class="highlight"/>Your target amount <br/> <input class="highlight" name="nn" size="5" /> Length of the period of savings<br/> </form> <?php if (isset($_POST['target']) && $_POST['nn']>5) { $target = $_POST['target']; $n = $_POST['nn']; $freq = $_POST['Frequency of Payment']; if ($freq == "monthly") {$m = 12;} else if ($freq == "Yearly") {$m = 1;} else if ($freq == "Half-yearly") {$m = 2;} else if ($freq == "quarter-yearly") {$m = 4;} $result = mysql_query("SELECT * FROM list1 WHERE minimum <= {$target} ORDER BY i_rate DESC LIMIT {$number_result}"); if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $administration_year = $row['administration']; $i = $row[[color="#008800"][size=2]'[/size][/color]i_rate']; $fee_rate = $row['fee']; $max_fee = $row['max_fee']; $ii = $i + 1; $iii = pow($ii,$n); $n_aid = round($n,0,PHP_ROUND_HALF_DOWN); $iii_aid = pow($ii,$n_aid); $iiii = $iii - 1; $iiii_aid = $iii_aid - 1; $iiiii = $iiii/$i; $iiiii_aid = $iiii_aid/$i; $n_adm = round($n,0,PHP_ROUND_HALF_UP); $pow_adm = (pow($ii,$n_vedeni)-1)/$i; if ($max_adm <> 0 && $fee_rate*$target*$iii>$max_popl) { $fee_amount = $max_fee; } else { $fee_amount = $fee_rate*$target*$iii; } $administration_total = $administration_year * $ii * $pow_adm; $state_aid = 2000 * $iiiii_aid; $s = $target - $state_aid + $administration_total + $fee_amount; $mm1 = $m+1; $mm2 = $m*2; $mmm = ($mm1/$mm2)*$i; $mmmm = 1+$mmm; $monthly_payment_amount = $s/($m * $iiiii * $mmmm); $savings = $monthly_payment_amount * $m * $iiiii * $mmmm; $profit = $savings + $state_aid - ($monthly_payment_amount * $m * $n) - $administration_total - $fee_amount; // according to this variable i want to sort the results, and $pu, $pv are created from user input, which i don't have it here, $traget is sql output. $s is a mix. /* RESULTS OUTPUT */ echo "<div class='results'>"; echo "Name of savings company: ".$row['name'] . " - "."Tariff: " . $row['Tariff']; echo "<br/>"; switch ($freq) { case "monthly": echo "Monthly payment: ". number_format(round($monthly_payment_amount,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc"." - "."Interest rate p.a: ".$i*100 . "%"; break; case "yearly": echo "Yearly payment: ". number_format(round($monthly_payment_amount,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc"." - "."Interest rate p.a: ".$i*100 . "%"; break; case "half-yearly": echo "half-yearly payment: ". number_format(round($monthly_payment_amount,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc"." - "."Interest rate p.a: ".$i*100 . "%"; break; case "quarter-yearly": echo "quarter-yearly payment: ". number_format(round($monthly_payment_amount,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc"." - "."Interest rate p.a: ".$i*100 . "%"; break; } echo "<br />"; echo "Savings: ". number_format(round($savings,2,PHP_ROUND_HALF_DOWN), 2, ',', ' '). " Kc"; echo "<br/>"; echo "Account fee: ". number_format(round($fee_amount,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ')." Kc"; echo "<br />"; echo "State aid (total): ". number_format(round($state_aid,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc"; echo "<br/>"; echo "Administration of account (total): ". number_format(round($administration_total,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') ." Kc for the entire year"; echo "<br/>"; echo "Total Profit: ". number_format(round($profit,2,PHP_ROUND_HALF_DOWN), 2, ',', ' ') . " Kc"; echo "<br/>"; } } } ?> The sql database has all the possible savings companies in my country. Now i need to tell the client which is the best. I calculate the profit, and i need to sort them by the profit. In the sql table profit isn't, as you can see by the code it is calculated later. But i need to tell the client which is the best As you can see i have sorted the results according to the interest rate, but the profit is not corelated only to it. I am trying also doing multiple order in sql, but can't see the profit being sorted from the biggest to the smallest. I am looking at the math formulas maybe s.m.th can be done in sql. The table has the following rows: company name; tariff; i_rate; administration fee; account fee (as % of target amount); max account fee.
  14. Yes i understood. The problem is in outputting the results back to the user. For the moment i do something like creating divs with while loop. Where each div has all the results needed from a bank. The next div has all the results of the other bank analogically. This variable which i want to do the sorting of the output (divs), is loacated within the while loop which fetches the sql results. Now the questions are: How is gonna be my new array feeded with the data? How are they gonna be outputted with each while loop?
×
×
  • 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.