<form id="select_info_form">
<button >Принять</button>
</form>
<?
require_once 'func.php';
$result=connectDB();
?>
<select id="sel">
<?foreach($result as $ras ):?>
<option id="op"><?echo $ras['name']?></option>
<?endforeach;?>
</select>
<script type="text/javascript">
$('#select_info_form').submit(function(e){
e.preventDefault();
$.ajax({
type:'POST',
url: 'ajax.php',
// dataType : "json",
data: $(this).serialize(),
success: function (data){
$('#op').html(data);
}
});
});
</script>
<?
$connect=new mysqli("localhost","root","","sii");//подключение к бд
$connect->query("SET NAMES 'utf8' ");
$result = $connect->query("SELECT * FROM pag ORDER BY name ASC ");
while (($row=$result->fetch_assoc())!=false) {
$str[]=$row;
}
echo $str;
?>
Сделал, что смог
бред собачий. Почитай как работает PHP и AJAX.<html>
<head>
</head>
<body>
<button id="get_data">Получить данные</button>
<select id="past_data">
<option selected disabled>-- Данных пока нет --</option>
</select>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script type="text/JavaScript">
$(document).on('click', '#get_data', function(event){
$.ajax({
type:'POST',
url: 'ajax.php',
dataType : "json",
success: function (data){
let options = '<option selected disabled>-- Выберите что-то --</option>';
for(let i in data){
options = options + '<option value="'+ data[i]['id'] +'">' + data[i]['name'] + '</option>';
}
$('#past_data').html(options);
}
});
});
</script>
</body>
</html>
<?php
$connect=new mysqli("localhost","root","","sii");//подключение к бд
$connect->query("SET NAMES 'utf8' ");
$result = $connect->query("SELECT id, name FROM pag ORDER BY name ASC ");
$response = [];
while (($row = $result->fetch_assoc()) != false) {
$response[] = $row;
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);