drop down button

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

ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

drop down button

Post by ekosoftco »

i was looking through google and didnt really see anything on this.
i was wondering if its possible, which im pretty sure it is, to have a form with a drop down button, and have different things happen according to which option is selected on the button when the form is submitted. Im thinking of having a spot where the member can edit members of his guild and choose to change their rank or delete them from the drop down button, and then hit the submit button and have it affect the database fields needed and all that good stuff.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Try:

Code: Select all

<form name = 'choice' action = 'choice.php' method = 'post'>
<select name = 'choice'>
<option value = '1'> 1 </option>
<option value = '2'> 2 </option>
<option value = '3'> 3 </option>
</select>
</form>

Code: Select all

echo $_POST["choice"];
Hope that helps,
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Code: Select all

<select name="action">
   <option value="delete">Delete this user</option>
   <option value="message">Message this user</option>
   <option value="hug">Hug this user</option>
   <option value="spank">Spank this user</option>
</select>
<input type="submit"/>
:?:

edit: Beat me to it ;-) I thought I was the only one up!
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

It's 9:28AM here. The day has just begun :)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Image
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

thanks guys
:mrgreen:
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

:x sry guys, i just realized, i have 3 options, admin, recruiter, and delete. i want it to add them to admin if they chose that, recruiter if they choose that, or delete them if they choose that, how do i set that to happen when you select that certain option?

and if it helps any to see, this is my code

Code: Select all

if($_GET['action'] == 'editmember')
{
        // start the table, make headers 
        echo '<table class="style3"><tr><th>Username</th><th>Character Name</th><th>Option</th><th>Submit</th></tr>'; 
        
        // fetch results from the DB 
        $result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error()); 
        
        // print each row 
        while($row=mysql_fetch_assoc($result)){ 
                echo '<tr style="background:#8ab4ff;">'; 
                echo '<td>'.$row['Uname'].'</td>'; 
                echo '<td>'.$row['Cname1'].'</td>'; 
				echo '<td><FORM name=guidelinks method=post action=guildcp.php?action=actionedit> 
<SELECT name="guidelinks" <OPTION SELECTED value="choose">--Choose--<OPTION value="makeadmin">Admin <OPTION value="makerecruiter">Recruiter <OPTION value="deletemember">Delete Member</SELECT>';
				echo '<td><input type=submit value=Edit></td></FORM>';
				echo '</tr>'; 
        } 
        // close the table 
        echo '</table>'; 
}
if($_GET['action'] == 'actionedit')
{
	if ($_POST['guidelinks'])
	{
	$result = mysql_query("UPDATE loginphp SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
	}
}
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

wrap ifs around the generation of options:

Code: Select all

if ($something) $optionList.= '<option ......
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

i dont quite understand how to do that :/
the generation of options part i mean, not sure what you mean, sry.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

OK right I may have misinterpreted your query. Perhaps you want to do something like this:

Code: Select all

<select onchange="this.form.submit()">
So that when a user makes a choice the form will be submitted immediately.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Code: Select all

if ($_POST["choice"] == "recruiter") {
  echo "Recruiter";
}
else if ($_POST["choice"] == "somethingElse") {
  //Do something else //
}
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

its not working, i always seem to be able to do the hard stuff, and get stuck on this easy stuff :/

Code: Select all

echo '<tr style="background:#8ab4ff;">'; 
                echo '<td>'.$row['Uname'].'</td>'; 
                echo '<td>'.$row['Cname1'].'</td>'; 
			 	echo '<td><FORM name=guidelinks method=post action=guildcp.php?action=actionedit> 
				<SELECT name="guidelinks" ><OPTION SELECTED value="choose">--Choose--<OPTION name="admin" value="makeadmin">Admin <OPTION 
				name="makerecruiter" value="makerecruiter">Recruiter <OPTION name="deletemember" value="deletemember">Delete Member</SELECT>'; 
                echo '<td><input type=submit value=Edit></td></FORM>'; 
                echo '</tr>'; 

        } 
        // close the table 
        echo '</table>'; 
}
if($_GET['action'] == 'actionedit')
{
	if ($_POST["choice"] == "makeadmin") 
	{ 
  	$result = mysql_query("UPDATE guilds SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
	} 
}
it goes to the actionedit
but doesnt do anything with the selection i choose
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

You're not using $_GET, you're using $_POST.
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

dont i have to have something for the form to go to as well? i have btoh $_GET and $_POST in there, because when you send the button, it goes to ?action=actionedit
then in actionedit i wanted it to read the post, although, i took it out and have this

Code: Select all

if($_GET['action'] == 'editmember')
{
        // start the table, make headers 
        echo '<table class="style3"><tr><th>Username</th><th>Character Name</th><th>Option</th></tr>'; 
        
        // fetch results from the DB 
        $result = mysql_query("SELECT * FROM loginphp WHERE Guild='{$_SESSION['Guild']}'") or die(mysql_error()); 
        
        // print each row 
        while($row=mysql_fetch_assoc($result)){ 
                echo '<tr style="background:#8ab4ff;">'; 
                echo '<td>'.$row['Uname'].'</td>'; 
                echo '<td>'.$row['Cname1'].'</td>'; 
			 	echo '<td><FORM name=guidelinks method=post> 
				<SELECT name="guidelinks" ><OPTION SELECTED value="choose">--Choose--<OPTION name="makeadmin" value="makeadmin">Admin <OPTION name="makerecruiter" value="makerecruiter">Recruiter <OPTION name="deletemember" value="deletemember">Delete Member</SELECT>'; 
                echo '<td><input type=submit value=Edit></td></FORM>'; 
                echo '</tr>'; 

        } 
        // close the table 
        echo '</table>'; 
}
if ($_POST["choice"] == "makeadmin") 
	{ 
  	$result = mysql_query("UPDATE guilds SET Admin='{$_SESSION['Uname']}' WHERE Tag = '{$_SESSION['Guild']}'") or die(mysql_error());
	}
and still it doesnt work.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Sorry, that was my mistake. I wasn't concentrating properly.
Post Reply