-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Ah! Two arrays $amts_due = [ '15' => 1088.00, '13' => 2206.00, '11' => 1716.00, '9' => 1210.00, '7' => 140.00 ]; $amts_paid = []; $payment = 5000.00; ksort($amts_due); // oldest first foreach ($amts_due as $bid => &$due) { if ($payment >= $due) { $payment -= $due; $amts_paid[$bid] = $due; $due = 0; } else { $due -= $payment; $amts_paid[$bid] = $payment; $payment = 0; } } $amts_due = array_filter($amts_due); $amts_paid = array_filter($amts_paid); Giving Due Array ( [13] => 272 [15] => 1088 ) Paid Array ( [7] => 140 [9] => 1210 [11] => 1716 [13] => 1934 )
-
When I created a test "icerik" table of 55 records and ran your code (with the double quotes around the query) it worked fine. This is the code I ran (changed the record counting bit) $results_per_page = 10; $sql='SELECT count(*) FROM icerik'; // get count of records in table $result = $conn->query($sql); $number_of_results = $result->fetch_row()[0]; $number_of_pages = ceil($number_of_results/$results_per_page); $page = $_GET['sayfa'] ?? 1; $this_page_first_result = ($page-1)*$results_per_page; $sql="SELECT * FROM icerik order by icerik_id desc limit $this_page_first_result, $results_per_page"; $result = mysqli_query($conn, $sql); foreach ($result as $r) { // output list of results echo $r['icerik_id'] . ' - ' . $r['name'] . '<br>'; } echo '<hr>'; for ($page=1;$page<=$number_of_pages;$page++) { echo '<a href="?sayfa=' . $page . '">' . $page . '</a> '; } RESULTS (page 1) RESULTS (Page 6)
-
That seems counter-intuitive to me. Startting with your original array, I would expect the remaining array, after customer pays 5000, to be 15 => 1088 13 => 272 where the 5000 clears the balance from the three oldest basket amounts (7, 9, 11) and leaves 272 due on basket 13
-
That is not the same as the line of code I suggested.
-
It's surprising that it shows any results at all. There is no code to output the results of the query. What's the full code, in the sequence you have it?
-
If you have any control over the format of your text file, you might want to consider something more convenient, such as an ini file format... [quote_lost_reason] ''= Price="Price" Product="Product" Other="Other" [Paul1] plist1="plist1" plist2="plist2" plist3="plist3" plist4="plist4" [Site Lighting] Interior="Interior" Exterior="Exterior" [credit] credit_note="Credit Note" then your processing would reduce to $data = parse_ini_file('myfile.ini', true); $wanted = $data['Paul1']; //wiew results echo '<pre>' . print_r($wanted, 1) . '</pre>'; Array ( [plist1] => plist1 [plist2] => plist2 [plist3] => plist3 [plist4] => plist4 )
-
Thank you for sharing that useless piece of information. Imagine we don't know what you expect to see we don't know what you are actually seeing
-
You are calculating the offset $this_page_first_result = ($page-1)*$results_per_page; but you don't use it in your LIMIT clause, so you always start at offset 0. Try... $sql="SELECT * FROM icerik order by icerik_id desc limit $this_page_first_result, $results_per_page";
-
The problem with that approach is that once you've counted them, you then have to go back to store the N items. I would us this logic...
-
When you are lost and want directions, it helps if you tell us where you want to go to. Why don't you tell us what you are trying to do. So far you have only told us how you are trying to get there. There could well be a better route. (And perhaps explain what that magical $vehicle object is and where comes from - it just pops up from nowhere in your code)
-
Probably as much use as Galen is to today's medical practitioners
-
Good idea. Do you think we should have something like this ?
-
If all you want is a row of date headings and a single row of totals, using PIVOT seems like overkill. <?php $res = $con->query("SELECT pay_date , SUM(amount) as total FROM income GROUP BY pay_date "); $data = $res->fetchAll(); $heads = "<tr><td>" . join('</td><td>', array_column($data, 'pay_date')) . "</td></tr>\n"; $totals = "<tr><td>" . join('</td><td>', array_column($data, 'total')) . "</td></tr>\n"; ?> <table border='1'> <?=$heads?> <?=$totals?> </table>
-
Have a try with simple_html_dom class
-
Stop posting duplicates of this topic.
-
PHP - How to take an image from an array and save it to MYSQL?
Barand replied to Zorglub's topic in PHP Coding Help
The solution was to use the correct variable! -
How do you expect me to answer questions like that when we don't have clue about what you are really doing. All we have is an abstraction of your problem. I have no idea what "filters" you are applying to other tables in the query. I am talking only about filters tht apply to "order" in this case. I don't know for sure if it is - I can't run your queries and time them - but you can.
-
fetch and display json array data stored in database
Barand replied to michelle1404's topic in PHP Coding Help
Each json message appears to be in a separate row in the table. I don't understand what you mean by "how to separate each json message." Do you mean just adding breaks in the output... $l1 = $con->prepare("SELECT msg, title FROM messages ORDER BY id DESC limit 4"); $l1->execute(); $cntmsg = $l1->rowCount(); foreach($l1 as $r1) { $m1 = $r1['msg']; $someJSON = $m1; $someArray = json_decode($someJSON, true); $pr1 = $someArray["data"]["commsettings"]; foreach($pr1 as $MyIndex => $MyValue) { echo $MyValue["name"] . '<br>'; } echo '<hr>'; } giving