ajax select list
ajax select list
I have a select list in my editor which currently uses a recordset from my ajax source to retrieve page names
$data['refpage'] = $db
->sql( 'SELECT DISTINCT refpage.PageID AS value, refpage.PageName AS label FROM refpage ORDER BY PageName ASC' )
->fetchAll();
which works, but isn't ideal for what i need.
what i want to do is retrieve the names of my php pages in my root folder and use these in my select list, so as new pages are added, the select list will always reflect this
i have created an array with the page names like so
$dir = $_SERVER['DOCUMENT_ROOT'];
chdir($dir);
$root_php_pages = glob("*.php"); //return all php files in the root folder
can anyone help me with the syntax to have the page name as 'label' and 'value' in my select list using this method ?
This question has an accepted answers - jump to answer
Answers
It sounds like you just need a
for
loop to run over the$root_php_pages
array. Better yet might be to use the array_map method which makes it very easy to build one array based on another.Allan
thanks Allan,
As I was using the pagename as both the label and the value, I used
to create my select list ;-)