Solved

Combo Boxes...

Posted on 2003-11-17
11
353 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
Industry Leaders: 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 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

690 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