I am looking for a way to display a list that contains the number of students per room, that is:
Ex:
HTML
<div class="form-group">
<select class="form-control" name="selecgrupo" id="selecgrupo">
<option>Seleccione Grupo</option>
</select>
</div>
<br>
JQUERY
$.ajax({
url: 'list_group',
type: 'POST',
})
.done(function(answer)
{
var result = $.parseJSON(answer);
for (var i = result.length - 1; i >= 0; i--)
{
$("#selecgrupo").append("<option value='" + result[i].id_grupo+ "'>" + result[i].grupo + "</option>");
}
})
.fail(function(){
console.log("error");
});
PHP
Returns the answer in JSON and with append ready the id and the group and in HTML I show that list ...
CONTROLLER
public function list_group(){
$response = $this->list_group_model->list_group();
echo json_encode($response);
}
MODEL
public function list_group(){
$sql= $this->db->conn_id->execute("
SELECT id_group, group
FROM grupos
ORDER BY group DESC");
return $sql;
}
Ex:
GRUPO A
GRUPO B
GRUPO C
You need to list that list with the number of students:
Ex:
GRUPO A 20
GRUPO B 11
GRUPO C 30
Thank you.