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=\'i ndex.php?f ilename=\' +this.opti ons[this.s electedInd ex].text;" >'."\n";
while ($file = readdir($dir))
{
if ((($file != '.')&&($file != '..')&&(filetype($file)==' file')))
{
echo '<option>'.$file."</option >\n";
}
}
echo "</select>\n";
closedir($dir)
Thankyou :)
$dir = opendir('/newusers/bja/');
echo '<select onClick="location.href=\'i
while ($file = readdir($dir))
{
if ((($file != '.')&&($file != '..')&&(filetype($file)=='
{
echo '<option>'.$file."</option
}
}
echo "</select>\n";
closedir($dir)
Thankyou :)
ASKER
Exactly want i want :)
Only thing is, can i make it so, it won't put the file if itselft?
Thanks
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
if($_GET["filename"]) {
echo "<option>$filename</option
}
loz
ASKER
No, i mean the file that is using the script...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
$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
loz
ASKER
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
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
change:
$thispage = explode("/", $_SERVER["PHP_SELF"]);
to:
$thispage = explode("/", $_GET["filename"]);
loz
ASKER
I think you were a bit confused, but i figured it out anyway :P
if($_SERVER["HTTP_HOST"]." /".$file != $_SERVER["HTTP_HOST"].$_SE RVER["PHP_ SELF"])
Thankyou for your help, i'm accepting ur response :)
BJA
if($_SERVER["HTTP_HOST"]."
Thankyou for your help, i'm accepting ur response :)
BJA
<?
$dir = opendir('/newusers/bja/');
echo '<select onClick="location.href=\'i
if($_GET["filename"]) {
echo "<option>$filename</option
}
while ($file = readdir($dir)) {
if ((($file != '.')&&($file != '..')&&(filetype($file)=='
if($file != $_GET["filename"]) {
echo "<option>$file</option>\n"
}
}
}
echo "</select>\n";
closedir($dir);
?>
i think this is what you want
loz