-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
@maviyazilim you are always outputting the last 10 in descending order. You should be outputting the results of the paginated query
-
non-English language issue in creating php array from CSV file
Barand replied to thara's topic in PHP Coding Help
What charset is the google one using? -
The variables $greeting and $late do not exist within the function. You will need to pass them as arguments or define them within the function.
-
non-English language issue in creating php array from CSV file
Barand replied to thara's topic in PHP Coding Help
Yes, but what charset is the CSV? Also, does this apply to your setup (from str_getcsv in manual) -
non-English language issue in creating php array from CSV file
Barand replied to thara's topic in PHP Coding Help
Was the csv created using utf8? -
non-English language issue in creating php array from CSV file
Barand replied to thara's topic in PHP Coding Help
Have you specified a compatible charset for your page, such as UTF8? -
Not unlimited though
-
As you have not shown us this homepage (where the error is showing itself) then you have had us chasing our tails and wasting time on the wrong piece of code. I've had enough. If you're lucky, someone else might take over. Bye.
-
Are you telling us that the code you posted here is not the code you used to output the list?
-
Despite requests, you refused to show any code that output the query results. On top of that you used "SELECT * " which gives us no information whatsoever about the columns you are selecting. As I told you, I created a test "icerik" table. This had columns "icerik_id" and "name" - which is why I output a column called "name". You need to use your column names, whatever they are.
-
Help with depreciated 'each' function replacement
Barand replied to sks2416's topic in PHP Coding Help
I've seen lots of images with captions. I've also seen lots of images with a caption and a sub-caption. What I haven't seen are images with a caption, sub-caption, sub-sub-caption et al. Perhaps naming the columns "Caption" and "Subcaption" (without the number suffices) will allow you to sleep tonight -
Help with depreciated 'each' function replacement
Barand replied to sks2416's topic in PHP Coding Help
I knew when I was writing that there would be some purist raising an objection. However I decided the returns in this case weren't worth the extra effort and took a pragmatic approach. -
Help with depreciated 'each' function replacement
Barand replied to sks2416's topic in PHP Coding Help
+1 to the bad DB design. Instead of +-------+-----------------+------------------------+------------------------+ | id | image_url | img_cap_1 | img_cap_2 | +-------+-----------------+------------------------+------------------------+ | 1 | imgA;imgB;imgC | capA_1; capB_1;capC_1 | capA_1; capB_1;capC_1 | +-------+-----------------+------------------------+------------------------+ you should have +-------+-------------+---------------+--------------+ | id | image_url | img_cap_1 | img_cap_2 | +-------+-------------+---------------+--------------+ | 1 | imgA | capA_1 | capA_2 | | 1 | imgB | capB_1 | capB_2 | | 1 | imgC | capC_1 | capC_2 | +-------+-------------+---------------+--------------+ -
Help with depreciated 'each' function replacement
Barand replied to sks2416's topic in PHP Coding Help
Use foreach() -
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...