php循环,暂停并在用户单击按钮时继续

I have 2026 image records to display on screen and it's too many to show all at once. I want to display the first 50, pause, wait for user to click a button. Then list the next 50, and so on. Is this a good solution? How can I do this? I want to echo javascript commands with php to display groups of 50 records.

<?php

$X = 0; $limit = 1000;

foreach ($i; $i <= $limit; $i++) {

$X++;

echo "<div> </div>";

if ($X % 50 == 0) 

{echo '<button> continue </button>';}

}
?>

PHP is a server language. You send a request, it gives you a response, there is no interactivity. You need to look into AJAX to get the result you want.