This code work for one selectbox and when find value he stop even if exist more column with same value.
I need to work for many select box, and to populate table with all rows with same column value (value.that the user chooses with select boxes)
Different table, but still the same concept. That whole approach with $sql->setFetchMode(PDO::FETCH_ASSOC); is very numbing. It is appropriate to define a fetch mode in the options when you create your PDO connection. The way you are trying looks to be an old school which has other better ways anyways besides that. You can use setAttribute to set the default fetch mode. That’s a better alternative. However I highly suggest you do it the right way by defining it in the PDO connection.
Another problem I see in your snippet, you are using isset($_POST['predmet'])) which is the same as isset($_POST['submit']) or isset($_POST). This is a rookie move which mostly is taught by websites like w3schools. These are old methods that are basically “hacks” if you will of checking for form submission. The proper way is using $_SERVER['REQUEST_METHOD'].
Thank you so much. I need just one more thing, When table is generated save in the session and everytime when user is log in, table to be on the page. And selectbox When table is generated save in the session and everytime when user is log in, table to be on the page, and selectbox also.
So put your $_POST['predmet1'] into the session when it is set.
And change the condition to check session as well:
// check POST and SESSION
if (isset($_POST['predmet1']) || isset($_SESSION['predmet1'])) {
// get ID from POST or SESSION
$predmet1 = isset($_POST['predmet1']) ? $_POST['predmet1'] : $_SESSION['predmet1'];
// and store it into the session
$_SESSION['predmet1'] = $predmet1;
// get rows
$rows = get_info($db, $predmet1);
// ... the rest of the code ...