Link to home
Start Free TrialLog in
Avatar of ChrisAnnable
ChrisAnnable

asked on

Combo Boxes...

The following code works fine, BUT for the combo box (<select>), I want wateva is the variable $filename to be put first in the combo box and all the other files listed afterwards.... at the moment, it just does it in alphabeticall order...

$dir = opendir('/newusers/bja/');

echo '<select onClick="location.href=\'index.php?filename=\'+this.options[this.selectedIndex].text;">'."\n";

while ($file = readdir($dir))
{
if ((($file != '.')&&($file != '..')&&(filetype($file)=='file')))
{
echo '<option>'.$file."</option>\n";
}
}

echo "</select>\n";

closedir($dir)

Thankyou :)
Avatar of lozloz
lozloz

hi,

<?

$dir = opendir('/newusers/bja/');

echo '<select onClick="location.href=\'index.php?filename=\'+this.options[this.selectedIndex].text;">'."\n";
if($_GET["filename"]) {
  echo "<option>$filename</option>\n";
}
while ($file = readdir($dir)) {
  if ((($file != '.')&&($file != '..')&&(filetype($file)=='file'))) {
    if($file != $_GET["filename"]) {
      echo "<option>$file</option>\n";
    }
  }
}
echo "</select>\n";

closedir($dir);

?>

i think this is what you want

loz
Avatar of ChrisAnnable

ASKER

Exactly want i want :)

Only thing is, can i make it so, it won't put the file if itselft?

Thanks
how do you mean exactly? do you mean not put the file in the combo box at all? if so you want to remove the following lines:

if($_GET["filename"]) {
  echo "<option>$filename</option>\n";
}

loz
No, i mean the file that is using the script...
ASKER CERTIFIED SOLUTION
Avatar of lozloz
lozloz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just relised that, the code u have doesn't actually check the url of the file its self (eg. $page = index.php), i need it to check the entire URL to that file and if it is, don't display it :)

Thankyou
that's what this part does:

$thispage = explode("/", $_SERVER["PHP_SELF"]);
$countpage = count($thispage) - 1;
$page = $thispage[$countpage];

$_SERVER["PHP_SELF"] holds the name of path information of the page e.g /admin/index.php. explode splits this string by "/" into an array, and after counting the number of elements in the array, $page stores the last element which should be the filename. the line if($file != $page) { checks that the file being put in the select box is not the same as the current page. that's the theory at least, i assume you posted because it's not working so i'll test it now and try and fix it

loz
well it seems to work with me in its present form

loz
if i put:

http://website.com?filename=index.php

in the url, it works...

BUT, if you put http://website.com?filename=/newusers/bja/index.php

it doesn't detect it as the same file!?

How can i fix this...

Thankyou
sorry i was using the filename itself rather than the variable filename..

change:

$thispage = explode("/", $_SERVER["PHP_SELF"]);

to:

$thispage = explode("/", $_GET["filename"]);

loz
I think you were a bit confused, but i figured it out anyway :P

if($_SERVER["HTTP_HOST"]."/".$file !=  $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"])

Thankyou for your help, i'm accepting ur response :)

BJA