Solved

display array as checkbox list

Posted on 2013-05-31
3
337 Views
Last Modified: 2013-05-31
Hi, I have a script as attached. When I run this only the last value is displayed as a checkbox but not the complete array. When I run print_r($ext) and array is displayed :Array ( [0] => 204 [1] => 205 [2] => 207 )  but the check box list only show 207. Help pls? Thank you.

A
 foreach($ext_array as $ext)
     {
                $vSelect ='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";
               
                          }
}

Open in new window

0
Comment
Question by:aej1973
3 Comments
 
LVL 6

Accepted Solution

by:
Robert Saylor earned 350 total points
ID: 39211446
change

$vSelect ='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";

to

$vSelect .='<input type="checkbox" id="extsn" name="extsn[]" value="' . $ext . '" />' . $ext.'<br />' ."\n";
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 50 total points
ID: 39211507
In PHP the single equal sign is the assignment operator.  The single dot is the concatenation operator.  When you use them together like this...

$a .= $b;

... Your telling PHP to take the string value of $b and append it to the rightmost end of the string value of $a, then replace $a with the resulting concatenation.  When you use just the equal sign like this...

$a = $b;

... you're telling PHP to take the data type and value of $b and overwrite $a with it.  It's a common mistake in PHP coding to accidentally omit some of this fiddly punctuation!
0
 

Author Comment

by:aej1973
ID: 39211599
Thank you very much for your quick response. It worked!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now