Infinite scroll (General)

by Andy, Thursday, November 05, 2015, 16:44 (3088 days ago)

Ok here's another one...

I'm trying to implement an infinite scroll technique, this is to try and cut the time it takes to display the posts, so that the select is not having to query the whole '***_entries' table every time

As a temporary fix, I first edited the query in index.inc.php to have a limit of 2000, as my users generally do not click more than 20 pages back.

$result=mysqli_query($connid, "SELECT id, tid FROM ( SELECT * FROM ".$db_settings['forum_table']." ORDER BY id DESC LIMIT 2000 ) sub...

This works in terms of speed but not it's not really satisfactory.

So I'm trying to implement 'Infinite Ajax Scroll' - it's getting there but hitting a brick wall now. I've correctly added the script code and link, and here's where I've got to in the php:

$limit = 50;
$start = ($page * $limit) - $limit;
$sql = "SELECT * FROM ".$db_settings['forum_table']." ORDER BY id DESC"; 
 
$result=mysqli_query($connid, "SELECT id, tid FROM (".$sql." LIMIT $start,$limit) sub WHERE pid = 0 ORDER BY sticky DESC, ".$db_thread_order." ".$descasc." ") or raise_error('database_error',mysqli_error());
 

IAS is just stating 'no more posts' when scrolling to the bottom of the screen because I presume that the variable $start is not updating. I can't get my head round how or where $result will update if the page is scrolled down to the bottom, and where the code should go in the template or in the .inc file.

Would you be able to shed any light on this please, or indeed have you thought about implementing an infinite scroll option in mlf?

In summary all I am trying to do is to select and load say 50 entries from the database, rather than having to select all of them every time. When users are flicking between boards it does make a big difference.

Thanks in advance.

Avatar

Infinite scroll

by Auge ⌂, Wednesday, November 11, 2015, 09:57 (3083 days ago) @ Andy

Hello

Only for clarification: infinite scroll means only to load the first X threads or postings into the aggregation view of all threads and load the next X threads or postings when arriving at the bottom of the page?

IAS is just stating 'no more posts' when scrolling to the bottom of the screen because I presume that the variable $start is not updating. I can't get my head round how or where $result will update if the page is scrolled down to the bottom, and where the code should go in the template or in the .inc file.

If the variables $start and $result are PHP variables they can't be updated because the PHP script ist not working in this moment. It's work ended in the moment, when the page was delivered to the browser of the user.

Would you be able to shed any light on this please, or indeed have you thought about implementing an infinite scroll option in mlf?

In summary all I am trying to do is to select and load say 50 entries from the database, rather than having to select all of them every time. When users are flicking between boards it does make a big difference.

Ok, let's have a look into the tasks.

1. Load the first X threads/postings in case of the first request (as usual).

2. Check permanently for the position of the page inside the browser window with JavaScript. We have to know, when the viewport of the browser arrives at the (actual) bottom of the page.

3. Send a request for the next X threads/posting via Ajax/JavaScript to the server when arriving at the bottom of the page. Show a "I'm busy" message to signalise that something goes on until item 4 is done.

4. The request will be sent to a PHP script, wich itself sends a query to the database and sends the result back to the Ajax/JavaScript routine.

5. Take back the result of the request and generate the output into the HTML document with the JavaScript routine.

6. Back to item 2.

And, not to forget, load the overview page with normal behaviour, if JavaScript is deactivated or not available.

Tschö, Auge

--
Trenne niemals Müll, denn er hat nur eine Silbe!

Infinite scroll

by Andy, Monday, February 15, 2016, 11:08 (2987 days ago) @ Auge

Thanks again for your time and explanation. I am back on this now, and will let you know how it goes...

RSS Feed of thread