Pausing form display

I have a large MySQL database. I built an HTML search page to limit the results and then a PHP page to display the results to either update or delete. My problem is that there is often many responses to my query and the form just repeats down the page and beyond.

I’ve read a lot on the web and understood that if I learned JavaScript that would solve my problem. I’ve gone through two complete video series of videos and now have a vague understanding of JS but when I try to work it into my code it doesn’t work. Then I read something that it can’t be done with JS.

Is there any way of pausing the form displays either using PHP and/or JavaScript? Or something else. It’s not the end of the world but it would be so much easier if it would stop after each result/form and I could hit a “Next” button to get the following record.

Thanks

I think (and I’m no expert) that you’d normally do this with pagination - you already mentioned that you’re limiting the results, so you’d draw perhaps ten results and a ‘next’ button, and a ‘previous’ button once you’re part way through the result set. Use the LIMIT keyword in the query to set the start position and number of results returned. Or you could create an array with the results, and use a form and (probably) Javascript to allow you to move around the results array to edit them.

A bit more detail might help others give more useful information. I don’t think you have to use Javascript to solve the problem, just have a look around here for stuff about multi-page forms and query results pagination.

1 Like

Thank you. I’m self taught at PHP too and not very good yet. I was unaware of the limit command. I don’t know if it will solve my problem but I’ll read further and see if I can find a way to get it to ‘continue’ after limiting it to one record. Again, thanks.

You can use LIMIT to specify the number of records returned, and the starting record. LIMIT 10 returns the first ten records, LIMIT 9,10 returns the “next” ten because we start at record nine (record count is base zero) and go on for ten more, LIMIT 19,10 the next page, and so on. So one easy way would be to keep a hidden variable in your form which contains the current record number (or start record number, if your form has more than one record) and when you press the ‘next’ button, retrieve that as a $_POST and use it to calculate the next or previous record(s) to display.

@droopsnoot thanks for the help. I played around with loops and the limit command yesterday but I haven’t quite got it yet. Once I’ll find a solution I’ll post it. Thanks again.

Well after two more days spent reading and trying stuff I finally read an article that explained things well enough for even this rookie programmer to understand. Where PHP is a server side programming language you just CAN NOT pause the execution of the script. It’s processed on the server and then the results, in one fell swoop, comes back. I guess I’ll just have to figure out a way to better limit the results.

Thanks again to @droopsnoot for his try at helping.

Sorry, I figured you would have seen that at the start - you are correct, by the time it gets to browser output, your PHP code is basically finished executing. There are ways though - just read up on pagination, it’s a common technique for splitting search results into pages etc.