0

I'm looking for an implementation of a simple button to load some elements at time. Around the web, after many days of searches, i have found a lot of examples but all based on mySQL database, and nothing similar to my case. I'm wondering, is it so difficult to implement this function? Need to do this, due to better performance.

For example: When the page loads, it should load the first 9 elements of the foreach loop, after click the button, other 9, etc etc... Easy to explain, but not to do. :(

Here I have this test code, and I would like to start with this:

<?php

?>
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.min.js"></script>

        <script>
            $(document).ready(function() {
                $("#loadmore").click(function(e) {
                    $.ajax({
                        type: 'POST',
                        data: { // },
                        cache: false,
                        success: function(test) {
                            // What need to do here?
                        }
                        error: function(err){
                            alert("Error!");
                        }
                    });
                    e.preventDefault();
                });
            });
        </script>

    </head>
    <body>
        <?php
        $db_txt = "dblinks.txt";
        $dblines = file($db_txt);
        foreach($dblines as $key => $links) {
            echo $links."<br>\n";
        }
        ?>

        <input type="button" id="loadmore" value="Show More" />

    </body>
</html>

For my basic knowledge about php, jquery, ajax, i need your help. Please. Thanks a lot.

1stthomas
  • 731
  • 2
  • 15
  • 22
Devilix
  • 334
  • 3
  • 13
  • This may help you out a bit: https://stackoverflow.com/questions/514673/how-do-i-open-a-file-from-line-x-to-line-y-in-php – IncredibleHat Oct 31 '17 at 17:23
  • The reason why it is in MySQL is because that is where the information is stored. You read just the number of query results you need for each page, this way avoiding storing to much data in memory. From your post can I assume your storage is a text file? If so, you need to read your file line per line and output the result, up to a certain number of lines. See the link Randall posted above for how to do that. – Nic3500 Oct 31 '17 at 17:25
  • OT: Curious why you cannot use mysql... it is certainly better performance to use a proper database over what I may assume is a very large file of static data? – IncredibleHat Oct 31 '17 at 17:28
  • I don't use mySQL because i don't know how to create the queryes...repeat, i have basic knowledge :( – Devilix Oct 31 '17 at 17:31
  • 2
    @Devilix Very easy to learn, and will definitely be way more useful to you in the future. – GrumpyCrouton Oct 31 '17 at 18:15
  • What database are you using? – nicolascolman Oct 31 '17 at 18:55
  • @nicolascolman I'm using a simple txt file. Can you help me? – Devilix Oct 31 '17 at 19:58
  • What did you try? – nicolascolman Oct 31 '17 at 22:08
  • @nicolascolman For the moment, nothing... because i don't know how to "join" php and jquery parts... seems that nobody knows how to help me :( – Devilix Nov 01 '17 at 02:59
  • Nobody can help me??? :( – Devilix Nov 04 '17 at 18:23

0 Answers0