ajax select list

ajax select list

crush123crush123 Posts: 417Questions: 126Answers: 18

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

  • allanallan Posts: 61,824Questions: 1Answers: 10,131 Site admin
    Answer ✓

    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

  • crush123crush123 Posts: 417Questions: 126Answers: 18

    thanks Allan,

    As I was using the pagename as both the label and the value, I used

    $data['refpage'] = array_combine($root_php_pages, $root_php_pages);
    

    to create my select list ;-)

This discussion has been closed.