![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Form Help
Ok I'm somewhat knowing PHP and I wanted to write a php script for a website my friend owns. Well any way. I was wondering is it possible to put like
[php] echo "<select name=\"example\" size=\"45\"> <option>1</option> <option>2</option> </select>"; [/php] And put it into array? Or just use like above? Or is I can put it into an array how would I be able to get the user to select the option from the array? |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
I suggest that you just keep it in HTML.
__________________
From the bottom of the stone steps... ...i'm calling still. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2005
Posts: 44
Rep Power: 0
![]() |
you could do it like this,
Create an array at the top of the php file with the options on want to use, like this [PHP] $options = array{ 'option1', 'option2' }; [/PHP] then at the place where you would like the selection box to appear try this [PHP] echo '<select name="example" size="45">' foreach($options as $option){ echo '<option>'.$option.'<option>'; } echo '</select>'; [/PHP] if my coding is correct then anything you add to the options array will be added to the select box at runtime hope it helps Magic E |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2006
Posts: 4
Rep Power: 0
![]() |
Here was my homework... Show you as an example.
$ContactCode = array ("E","P","A"); $ContactChannel = array ("E-M@il","Phone","Address"); <BR>You want me to contact you via :: <select name="ContactBack"> <?php for ($i=0;$i<3;$i++) { $SelectChannel=""; if ($ContactBack == $ContactCode[$i]) $SelectChannel="selected"; print "<option value = '$ContactCode[$i]' $SelectChannel> $ContactChannel[$i]"; } ?> </td></tr> </select> |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Seaminem, please read the forum's rules/FAQ and learn to put your code in tags. Any snippet larger than you posted would gag a maggot. See the previous posts for what I mean.
@the OP: magic_e's example is good. Despite the advice of darkone, there is a place for html generated on the server. The structure of some page may vary from one circumstance to another. If this circumstance is known on the server side, then the PHP code can generate the appropriate page by emitting html in response to conditional constructs. I usually put large, unchanging blocks of HTML in the document directly (turn off PHP processing with the ?>, put in HTML, reenter PHP with the <?PHP). There is also the "Here document" syntax available for large blocks.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|