PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 27th, 2002, 10:20 PM
hardseeker hardseeker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 64 hardseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
gettting values of select options from form

i have a form that has a varied number of select options.

after the form is posted, it goes to a php file.

in the php file, in a while loop, i have a $count++

how do i get the value inside $Cm1 or $Cm2 or ... $Cm100


for ($a=0;$a<=100;$a++) {
// process
}

by doing something like

$var = $"Cm"."$count";

currently, this only has the value "Cm1"

and

$$var has the value of "$Cm1" ?


// echo "$Cm1 <p> "; // this works
// echo "$Cm2 <p>";
__________________
perl / cgi newbie

Reply With Quote
  #2  
Old November 27th, 2002, 10:55 PM
vig0 vig0 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 3 vig0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 53 sec
Reputation Power: 0
you could try:

PHP Code:
while (list($key$value) = each ($_POST)) {
  if (
substr($key02) == "Cm") {
    echo 
"Key = $key; Value = $value<br>";
  }



That should loop through the $_POST array and display only the name and value of the variable that begins with "Cm".

I hope this is what you meant.

Regards.
v.

Reply With Quote
  #3  
Old November 27th, 2002, 11:00 PM
micros_bytes micros_bytes is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Posts: 790 micros_bytes User rank is Corporal (100 - 500 Reputation Level)micros_bytes User rank is Corporal (100 - 500 Reputation Level)micros_bytes User rank is Corporal (100 - 500 Reputation Level)micros_bytes User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 10 h 29 m 56 sec
Reputation Power: 10
Have you created the selects as an array in your HTML form?

For example:
PHP Code:
<select name=cm[]>
     <
option value="somevalue1">Some Text 1</option>
     <
option value="somevalue2">Some Text 2</option>
</
select>

<
select name=cm[]>
     <
option value="someothervalue1">Ohter Text 1</option>
     <
option value="someothervalue2">Other Text 2</option>
</
select


If you create the selects as an array in the form, you can access them as you would any other array in PHP.

For example:
PHP Code:
if(isset($_POST['cm']))
{
    
$num count($_POST['cm']);
    for(
$i==1;$i<=$num;$i++)
        {
           
$j $i-1;
           
$arr $_POST['cm'][$j];
            }
    } 

Reply With Quote
  #4  
Old November 29th, 2002, 03:20 AM
hardseeker hardseeker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 64 hardseeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
for loop
{

echo "<select name=Cm"; echo "$count"; echo "><option>n</option> <option>y</option></select>";

echo "<select name=Cm"; echo "$count"; echo "><option>y</option></select>";

}

i need the value in the select object for processing.

is it good to make it an array ?

Reply With Quote
  #5  
Old November 29th, 2002, 12:53 PM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2001
Location: Ft Myers, FL
Posts: 4,205 kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1Folding Points: 117001 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 3 Weeks 9 h 44 m 42 sec
Reputation Power: 573
Send a message via ICQ to kicken Send a message via AIM to kicken Send a message via MSN to kicken
Arrays would be eaiser to use. Just use cm[] rather than a counter for the name. PHP Will automatically make them an array.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > gettting values of select options from form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT