Request to start PHP / MySQL on button click / click

I wonder if it is possible to start / restart a mysql query when clicking / clicking a button / link?

Basically, I run a query that limits the results to the first 7, when I click the button below the results to show more results. When the button is pressed / pressed, I need to re-run the request and set a limit of, say, 20.

Any help / advice on how to do this would be greatly appreciated. Thanks in advance, S.

+3
source share
1 answer

The code to run the query and get the results is on the server, and the button is in the browser, so you need to somehow contact the server to get more results. You can use the Ajax call and update the contents of your page dynamically or just make a link and get another page with a lot of results.

You already have a code that returns 7 results and shows them on the page - let them say that your page shows seven: www.blah.com/show. You can add a parameter to your page that takes the number of results to display, for example. www.blah.com/show?num=7. Now, instead of hard-coding SQL to read the seven results, you first read the parameter and use that number in your query. Link to show more results can now be<a href="www.blah.com/show?num=20">Show more</a>

Ajax , , <a> , ( jQuery) $.ajax() . .

+4

Source: https://habr.com/ru/post/1768035/


All Articles