Page 1 of 3

using a combo box to display dir

Posted: Tue Oct 10, 2006 2:57 pm
by Obadiah
when i execute this block....instead of giving me a dropdown it just prints straight across
and i cant figure out why

Code: Select all

<?php
session_start();
$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");

while(!(($file = readdir($dh)) === false))
{ 

		if (is_dir("$dirname/$file"))
	{
		echo "(D) ";
	}
		echo "<option value='Select Type'";
		echo " selected";
		echo ">$file\n";
      echo "</select>";
}
closedir($dh);
?>
shouldent this work?!? :?

[edited]

lol...if its not working because i forgot to open the tag im gonna shoot myself :lol:

Posted: Tue Oct 10, 2006 3:08 pm
by feyd
not having the opening tag can create issues.

Posted: Tue Oct 10, 2006 3:12 pm
by Obadiah
ok....figured it out....but now it makes a new dropdown for each directory insted of putting them all in the same one....my suspision is because of the while loop i have....how can i rewrite this so that they all show up in one

Code: Select all

<?php
session_start();
$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");

while(!(($file = readdir($dh)) === false))
{ 
		echo "<select>";
		echo "<option value='Select Type'";
		echo " selected";
		echo ">$file\n";
      echo "</select>";
}
closedir($dh);
?>

Posted: Tue Oct 10, 2006 3:14 pm
by Obadiah
feyd wrote:not having the opening tag can create issues.
:oops: ...i cant belive i missed that...even worse....posting because i couldnt see it

Posted: Tue Oct 10, 2006 3:20 pm
by feyd
Moving the opening and closing tags outside of the while loop will make all the options go into a single box.

Posted: Tue Oct 10, 2006 3:44 pm
by Obadiah
sweet!....thats a awful one to miss also :lol: ....what could i do if i was wanting to create another select box and depending on whatever the directory is of the previous one it displays that directory....how could i go about doing that? i know it would look similar to what i have....i know id have to use a get /post method and i know that means ill prolly have to name the first combobox, i cant think of where to start first though :?

Posted: Wed Oct 11, 2006 8:54 am
by Obadiah
originally i had this and it does its job...for what im using it for

Code: Select all

<?php
session_start();
$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");
echo "<select>";
while(!(($file = readdir($dh)) === false))
{ 
		
		echo "<option";
		echo ">$file\n";
}
      echo "</select>";
	
closedir($dh);
?>
but then i tried to figure out a way to get the value of file after the while had been executed....so if the user would select one of the directories listed in that combo box it will bring up a new combobox with a list of files or folders in that directory
and continue on that way until the user selects a file...then it brings it up for them
so i tried this

Code: Select all

<?php
session_start();
$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");
echo "<select>";
while(!(($file = readdir($dh)) === false))
{ 
		
		echo "<option";
		$val1 = echo ">$file\n";
}
      echo "</select>";
if $val1(is_dir("$dir/($file = readdir($dh)")));
{
	while(!(($file = readdir($val1)) === false))
	{ 
		
		echo "<option";
		echo ">$file\n";
	}
		echo "</select>";
}

closedir($dh);
?>
this is the error that im getting
Parse error: parse error, unexpected T_ECHO in C:\Program Files\xampp\htdocs\Log_In\agent\resid_report.php on line 10
im guessing its not liking where i tried to get the value of the echo by naming the echo $val1 but how would i go about getting the value of $file after its been executed and whats a good way for me to go about doing what i need to do...anyone know of any tutorials or has anyone delt with this?

Posted: Wed Oct 11, 2006 12:50 pm
by Obadiah
ok....i tried this....it seems to be ok...but i cant figure out how to call the selected action of the combobox in php....like if this folder is selected echo another combo box and search again....here is what i have

Code: Select all

<?php
session_start();

ini_set('error_reporting', E_ALL); 
ini_set('display_errors', 1); 

$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");
echo "<select>";
while(!(($file = readdir($dh)) === false))
{ 

		echo "<option";
		echo ">$file\n";
}
      echo "</select>";
      
      if ($file = 'selected')
      {
	      echo "<select>";
	      while(!(($file = readdir($dh)) === false))
{ 

		echo "<option";
		echo ">$file\n";
}
      echo "</select>";
      }
      
closedir($dh);

?>
i dont get any errors...it just doesnt work...and the echo has already printed the other select to the screen without anything in there

Posted: Wed Oct 11, 2006 12:55 pm
by John Cartwright
look very carefully at

if ($file = \\\'selected\\\')

something is missing :wink: Also please ignore the slashes, I\'m having some technical issues.

Posted: Wed Oct 11, 2006 1:40 pm
by Obadiah
i tried it several different ways....first i thought u were hinting something with your slashes so i tried this

Code: Select all

if ($file =\ 'selected\')
then i looked at your red = sign and did this

Code: Select all

if ($file == 'selected')//then with ===
then i thought about vb and did something like this

Code: Select all

if ($file.option = 'selected')
then i really took a bad turn with this

Code: Select all

if ($file.option = (isset('selected')))
then i changed my whole script because i read your comment again about something being missing and made it look like this

Code: Select all

<?php
session_start();
ini_set('error_reporting', E_ALL); 
ini_set('display_errors', 1); 

$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");
echo "<select>";
while(!(($file = readdir($dh)) === false))
{ 

		echo "<option selected =\";
		echo \">$file\n";
}
      echo "</select>";
      
      if ($file == 'selected')
      {
	      while(!(($file = readdir($dh)) === false))
{ 

		echo "<option";
		echo ">$file\n";
}
      echo "</select>";
      }
      
closedir($dh);

?>
:) i know im closer....another hint please!!!

Posted: Wed Oct 11, 2006 1:52 pm
by volka
php is executed server-side. It can only use the parameters sent to it be the client within the http request.
Everything is submitted as a string, mostly a name=value string pair.
php has no access to the client's document (object) model.

try

Code: Select all

<html>
	<head>
		<title>select test</title>
	</head>
	<body>
		<pre><?php print_r($_POST); ?></pre>
		<form method="POST">
			<div>
				<select name="xyz">
					<option value="1">a</option>
					<option value="2">a</option>
					<option value="3">a</option>
					<option value="4">a</option>
				</select>
				<input type="submit" name="submit">
			</div>
		</form>
	</body>
</html>
to see what is submitted how from a named select element on form submission.

Posted: Wed Oct 11, 2006 3:09 pm
by Obadiah
ok....i ran it and this is what i came up with

your app prints this out
Array
(
[xyz] => 2
[submit] => Submit Query
)
everytime a option is changed and you hit the submit query button it submits and prints out whatever the value of xyz is to the screen....so...theoretically

if i used a for loop that incremented by one each time the while executed, printing out a number for value like value="$i++" then changed dirname to add on whatever folder was selected at the end when the user hits submit it brings up another <select> with the new value of $file in it

ok...i tried this

Code: Select all

<?php
session_start();
ini_set('error_reporting', E_ALL); 
ini_set('display_errors', 1); 

$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");
for($i=1; $i=$file; $i++)
{
echo "<select name=\"{$i}\">";
while(!(($file = readdir($dh)) === false))
{ 

		echo "<option";
		echo ">$file\n";
}
      echo "</select>";
}      
closedir($dh);

?>
:oops: variable undefined...i chould have guessed that one so then i thought for nested in the while

Code: Select all

<?php
session_start();
ini_set('error_reporting', E_ALL); 
ini_set('display_errors', 1); 

$dirname = "resids/{$_SESSION['logname']}";
$dh = opendir($dirname) or die("couldn't open directory");

echo "<select name=\"{$i}\">";
while(!(($file = readdir($dh)) === false))
{ 
	for($i=1; $i=$file; $i++)
	{

		echo "<option";
		echo ">$file\n";
	}
}
      echo "</select>";      
closedir($dh);

?>
i still get a variable that is undefined by my E_All...which i dont quite understand and whats worse...now it seems i made a infinate loop :( am i getting further away?

Posted: Thu Oct 12, 2006 8:58 am
by Obadiah
can anyone tell me why i get the infinate loop and why its not working the way it should? please? :cry:

Posted: Thu Oct 12, 2006 9:01 am
by feyd
the second parameter to the for loop likely.

Posted: Thu Oct 12, 2006 9:09 am
by Obadiah
well thats exactly what im not understanding...if i took out the for loop the while loop($file) will show
2 folders....so i figured if i used a for loop that incremented by one each time file printed out a folder then i could use the new variable to somehow get the variable that the user selected kinda like volkas application....but when i tried that....i got an infinate loop...i dont understand why...i thought it should have worked....shouldnt it have?

am i going at the problem all wrong?