Solved

Combo Boxes...

Posted on 2003-11-17
11
350 Views
Last Modified: 2006-11-17
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 :)
0
Comment
Question by:ChrisAnnable
  • 6
  • 5
11 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9763175
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
0
 

Author Comment

by:ChrisAnnable
ID: 9763373
Exactly want i want :)

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

Thanks
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9763392
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
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:ChrisAnnable
ID: 9763461
No, i mean the file that is using the script...
0
 
LVL 13

Accepted Solution

by:
lozloz earned 100 total points
ID: 9763539
<?

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

$thispage = explode("/", $_SERVER["PHP_SELF"]);
$countpage = count($thispage) - 1;
$page = $thispage[$countpage];
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"]) {
      if($file != $page) {
        echo "<option>$file</option>\n";
      }
    }
  }
}
echo "</select>\n";

closedir($dir);

?>

ought to work..

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9766748
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
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9766818
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
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9766919
well it seems to work with me in its present form

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9769060
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
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9770672
sorry i was using the filename itself rather than the variable filename..

change:

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

to:

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

loz
0
 

Author Comment

by:ChrisAnnable
ID: 9785389
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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 46
Crazy text will not be removed no matter what I try! 13 30
php extract($_REQUEST) 5 54
Loop through multiple arrays 13 29
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question