Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Combo Boxes...

Posted on 2003-11-17
11
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Accepted Solution

by:
lozloz earned 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 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