PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 12:17 am
So I have this arrray which will glob() through my directory, and print all contents with .php extensions. basically I want to use this as an admin. panel, all files in this directory will have admin. properties.
Code: Select all
<select name="admin">
<?php
$files = glob("admin/*.php");
foreach ($files as $key => $value){
?>
<form method=post action=<?php $_SERVER['PHP_SELF'];?>>
<B>Choose from the list below</B><br><SELECT name=link size=16>
<OPTION VALUE ="<?php echo $key;?>"><?php echo $key;?>></OPTION>
<?php
}
?>
</select>
I also tried
Code: Select all
<select name="admin">
<?php
$files = glob("admin/*.php");
foreach ($files as $key){
?>
<form method=post action=<?php $_SERVER['PHP_SELF'];?>>
<B>Choose from the list below</B><br><SELECT name=link size=16>
<OPTION VALUE ="<?php echo $key;?>"><?php echo $files;?>></OPTION>
<?php
}
?>
</select>
And most possibilities in-between.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Oct 01, 2006 2:08 am
I am guessing that the generated HTML is messed up. You have a select outside and inside the loop and the form inside. Maybe something like this:
Code: Select all
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<b>Choose from the list below</b>
<br/>
<select name="link">
<?php
$files = glob("admin/*.php");
foreach ($files as $key => $value) {
?>
<option value="<?php echo $key;?>"><?php echo $key;?>></option>
<?php
}
?>
</select>
</form>
(#10850)
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 2:20 am
Thanks buddy, I'll be checking that out within the next few minutes. I was wondering where that went wrong hehe. most of my codes do go wrong at least at first...
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 2:26 am
Nope, same result.
It basically prints a blank select menu, not sure why yet though..
--thanks though.
Sean!
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Oct 01, 2006 2:50 am
If it prints a blank select then the "$files = glob("admin/*.php");" is not returning anything to $files. Probably a path or permission problem.
(#10850)
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 2:57 am
I would agree, but I can print from that directory no prob outside of this select script.
I have tried to glob them and make just a list of the uri's but I would like to make it in this format, because, it looks attractive, at least more-so than in another.
If you would like, I will print the contents of admin/ with a diff script, just to show you there is stuff there, and i do indeed have control over it, permissions wise everything is good : )
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 3:04 am
I know exactly what is wrong now. I made a slight oversight, one you would not have been able to forsee.
When writing this code, I first had it in my guestbook1 directory, I then modified the code to make it a dropdown, and in doing so also moved it into the admin directory hehe. So when you call for something in the directory we didn't need to specify admin/
Thank you for the help.
Sean!
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 3:08 am
Hmm, after testing it still doesn't act right..
I've tried with this, this file is in the same directory as the files i'm looking for.
Code: Select all
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<b>Choose from the list below</b>
<br/>
<select name="link">
<?php
$files = glob("/*.php");
foreach ($files as $key => $value) {
?>
<option value="<?php echo $value;?>"><?php echo $key;?>></option>
<?php
}
?>
</select>
</form>
I've also tried this
Code: Select all
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<b>Choose from the list below</b>
<br/>
<select name="link">
<?php
$files = glob("*.php");
foreach ($files as $key => $value) {
?>
<option value="<?php echo $value;?>"><?php echo $key;?>></option>
<?php
}
?>
</select>
</form>
Also to no avail.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Sun Oct 01, 2006 3:15 am
Well ... "/*.php" is the root directory and "*.php" is the current directory. It sounds like it isn't in either of those two (or "admin/*.php"). Keep trying.
(#10850)
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 3:18 am
Ok nevermind, I now have this solved.
Thanks for the help!
Code: Select all
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<b>Choose from the list below</b>
<br/>
<select name="link">
<?php
$files = glob("/*.php");
foreach ($files as $key => $value) {
?>
<option value="<?php echo $value;?>"><?php echo $value;?></option>
<?php
}
?>
</select>
</form>
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 3:37 am
I have a similar, but new problem. Basically now that we got control of that loop, I want it to create links to each of the files.
I have this so far, the only instance its worked is when I wrote the submit within the loop, which caused the one file, the first of the loop to print in the option, then the rest printed outside, yes as links and they did work, but not as expected, or needed. I only need them to work within the select box.
Code: Select all
<form method="POST" action="<?php $_SERVER['PHP_SELF'];?>">
<b>Choose from the list below</b>
<br/>
<select name="link">
<?php
#if arborint view this, I moved the file back guestbook1/ so to make it easier
$files = glob("admin/*.php");
foreach ($files as $key => $value) {
?>
<option value="<?php echo "<a href=" . $key . ">" . $key . "</a>";?>"><?php echo "<a href=" . $value . ">" . $value . "</a>"; ?></option>
<?php
}
?>
</select>
<input type="submit" value="go to!" name="submit">
</form>
Last edited by
akimm on Sun Oct 01, 2006 3:54 am, edited 1 time in total.
miro_igov
Forum Contributor
Posts: 485 Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria
Post
by miro_igov » Sun Oct 01, 2006 3:50 am
Why your select tag is closed after the submit button
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 3:53 am
Good point, I fixed that. However the php still is not doing what I need, any idea why?
Thanks!
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Oct 01, 2006 4:43 am
You have a/href elements in your option elements? Why?
This script will output "html" like
<option value="<a href=0>0</a>"><a href=admin/a.php>admin/a.php</a></option>
<option value="<a href=1>1</a>"><a href=admin/b.php>admin/b.php</a></option>
and that a bit ...strange.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sun Oct 01, 2006 4:46 am
I am trying to make the select menu allow the different selections to be different links. It is the begining of a admin panel.