Current location: Hot Scripts Forums » Programming Languages » PHP » Select an option


Select an option

Reply
  #1 (permalink)  
Old 08-03-06, 08:07 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Select an option

I have a select menu with 2 options:

-Show users
-Delete group

I want to show something if user select option 1 and something if user select option 2.

What I need to do to print a text if user select option 1 an print another text if user select option 2 ?

the following code don't do exactly what I need. (The IF statements) :

PHP Code:

<?php

  
if (isset($_POST['submit']) && ($_POST['select'] == 1)) {
  print 
"1";
}
  
if (isset(
$_POST['submit']) && ($_POST['select'] == 2)) {
   print 
"2";
}
  
print 
"<TABLE BORDER=2 CELLPADDING=2>\n";
print 
"<table width=\"500\" border=\"1\">";
print 
"<tr>\n";
print 
"<td>Group Name</td>\n";
print 
"<td>Users in group</td>\n";
print 
"<td>Options</td>\n";
print 
"</tr>\n";
  
print 
"<form action=\"groups.php\" method=\"post\">";
  
while (
$row mysql_fetch_array($groups)) {
print 
"<tr>\n";
print 
"\t<td>".$row['name']."</td>\n";
print 
"\t<td><center>".$row['nr_useri']."</center></td>\n";
print 
"<td><select name=\"select\">";
print 
"<option value=\"1\">Show users</option>";
print 
"<option value=\"2\">Delete Group</option></select>";
print 
"<input type=\"submit\" name=\"submit\" value=\"go\" /></td>";
print 
"</tr>\n";

}
Reply With Quote
  #2 (permalink)  
Old 08-03-06, 10:06 AM
Richard's Avatar
Richard Richard is offline
Wannabe Coder
 
Join Date: Sep 2005
Location: Oxford, UK
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
zoliky, this is the third thread you've made about your groups, and problems you're having. I'm sure people are more then happy to help, but it would be a lot easier if you kept all questions in one thread.

From what I can see you're trying to run functions depending on what option is checked. If option 1 is selected you want to show users, or if option 2 is select you want to delete the group. The simple way of doing this would be to insert MySQL queries into the IF statement, like you've nearly already done.
PHP Code:

if (isset($_POST['submit'])) {

    if (
$_POST['select'] == 1)) {
        
// Show Query
    
} elseif ($_POST['select'] == 2) }
        
// Delete Query
    
}

If you're trying to do a 'confirm' message, asking if the user wants to delete the group, then you'll need to use Javascript, as its client-side.
__________________
Richard.
Reply With Quote
  #3 (permalink)  
Old 08-03-06, 10:51 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks and sorry for many threads.

Yes i use the following PHP code:

PHP Code:

if (isset($_POST['submit'])) {

  if(
$_POST['select'] == ) {
    echo 
'Show all users selected for row'.$rowid;
  } elseif( 
$_POST['select'] == ) {
     echo 
'Delete group selected for row'.$rowid;
  }

Each row has an option menu and a submit button.Something like : http://img520.imageshack.us/img520/2563/grupuriyd9.gif

When user select the first option I want to see "The user select the FIST OPTION from row XX"

I use the following method :

print '<input type="hidden" name="rowid" value="'.$row['id'].'">';

and
PHP Code:

if (isset($_POST['submit'])) {

  
$rowid $_POST['rowid'];
  print 
$_POST['rowid'];
  if(
$_POST['select'] == ) {
    echo 
'Show all users selected for row'.$rowid;
  } elseif( 
$_POST['select'] == ) {
     echo 
'Delete group selected for row'.$rowid;
  }

But not work..
Any idea?
Reply With Quote
  #4 (permalink)  
Old 08-03-06, 12:10 PM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I solve the problem, work great now!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i output something the moment i click on an option under select tag? d_maniger06 JavaScript 2 06-10-06 01:07 PM
populate select option multilevel + javascript+php ikutluay JavaScript 3 03-14-06 02:07 PM
related select option from db javascr+php ikutluay PHP 0 03-06-06 08:32 AM
Multiple Select phppick JavaScript 3 04-11-05 12:09 AM
Select List insert into DB The Omega JavaScript 1 01-12-05 12:51 PM


All times are GMT -5. The time now is 07:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.