Help implement the drop-down list.
Model:
function_get () {
$ result = $ this- & gt; mysqli- & gt; query ("select * from t_gs_regions Order by gs_regions_name ASC");
$ n = $ result- & gt; num_rows;
For ($ i = 0; $ i & lt; $ n; $ i ++) {
$ row6 = mysqli_fetch_assoc ($ result);
$ REGIONS [] = $ ROW6;
}
Return $ regions;
}
Controller:
$ reg = region_get ();
View:
& lt; select name = "regions_id" & gt;
& lt; optional = "" & gt; vibese from the list & lt; / option & gt;
& lt;? php foreach ($ regions as $ r) :? & gt; {
'& lt; optional = & lt;? = $ r [' gs_regions_id ']? & gt; & gt; & lt;? = $ r [' gs_regions_name ']? & gt;' & lt; / option & gt; ';
}
& lt;? PHP EndForeach? & gt;
} else {
'& lt; optional = "" & gt; List of Inaccessible & LT; / Option & GT;';
}? & gt;
& lt; / select & gt;
Answer 1
If you have a MVC application, then something like something like is:
& lt;? php
Class Model
{
Private $ mysqli;
Public Function Getregions ()
{
$ result = $ this- & gt; mysqli- & gt; query ("select * from t_gs_regions Order by gs_regions_name ASC");
$ regions = array ();
if ($ result) {
While ($ row = $ this- & gt; mysqli- & gt; fetch_assoc ($ result)) {
$ regions [] = $ row;
}
}
Return $ regions;
}
}
? & gt;
& lt;? php
Class Controller
{
Public Function RegionAction ()
{
$ model = new model ();
$ regions = $ model- & gt; getregions ();
Return Array (
'regions' = & gt; $ regions
);
}
}
? & gt;
& lt; select name = "regions_id" & gt;
& lt; optional = "" & gt; vibese from the list & lt; / option & gt;
& lt;? php if (! empty ($ regions)) :? & gt;
& lt;? php foreach ($ regions as $ r) :? & gt;
& lt; optional = "& lt;? = $ R ['gs_regions_id'];? & gt;" & gt; & lt;? = $ R ['gs_regions_name']; ? & gt; & lt; / option & gt;
& lt;? php endforeach;? & gt;
& lt;? PHP ELSE:? & gt;
& lt; optional = "" & gt; List of Inaccessible & LT; / Option & GT; ';
& lt;? php endif; ? & gt;
& lt; / select & gt;
Answer 2
And if so:
function_get () {
$ result = $ this- & gt; mysqli- & gt; query ("select * from t_gs_regions Order by gs_regions_name ASC");
$ REGIONS = FALSE;
If (mysqli_num_rows ($ result) & gt; 0) {
$ regions = array ();
while ($ row6 = mysqli_fetch_assoc ($ result)) $ regions [] = $ row6;
}
Return $ regions;
}
and
& lt; select name = "regions_id" & gt;
& lt; optional = "" & gt; vibese from the list & lt; / option & gt;
& lt;? php if ($ regions) {foreach ($ regions as $ r) {? & gt; {
'& lt; optional = & lt;? = $ r [' gs_regions_id ']? & gt; & gt; & lt;? = $ r [' gs_regions_name ']? & gt;' & lt; / option & gt; ';
}
& lt;? php}? & gt;
} else {
'& lt; optional = "" & gt; List of Inaccessible & LT; / Option & GT;';
}? & gt;
& lt; / select & gt;