I’m having some problems generating an AJAX response with PHP. The response should be a associative array with the database values inside. These values are displayed in a selectbox afterwards.
if (isset($_POST['rolle'])) {
$sql = "SELECT rolle FROM pu_zugriff_rolle ORDER BY rolle ASC";
$result = mysql_query($sql);
$result = mysql_fetch_array($result);
echo json_encode($result);
}
There are several entries stored in the database but I only get the first database value twice as a result. The sql query is definitively not the problem.
I read somewhere the $result = my_sql_array($result); statement is needed to create an assiciative array. If I’m leaving it the statement out, it results in an empty selectbox.
You can do this: