Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 28th, 2005, 8:43 PM   #1
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
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?
KyrinComaBlack is offline   Reply With Quote
Old Dec 29th, 2005, 1:51 AM   #2
darkone916
Hobbyist Programmer
 
darkone916's Avatar
 
Join Date: Jul 2005
Location: Oman
Posts: 125
Rep Power: 4 darkone916 is on a distinguished road
Send a message via MSN to darkone916
I suggest that you just keep it in HTML.
__________________
From the bottom of the stone steps...
...i'm calling still.
darkone916 is offline   Reply With Quote
Old Jan 4th, 2006, 6:39 AM   #3
magic_e
Programmer
 
Join Date: Jan 2005
Posts: 44
Rep Power: 0 magic_e is on a distinguished road
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
magic_e is offline   Reply With Quote
Old Jan 30th, 2006, 4:18 AM   #4
seaminem
Newbie
 
Join Date: Jan 2006
Posts: 4
Rep Power: 0 seaminem is on a distinguished road
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>
seaminem is offline   Reply With Quote
Old Jan 30th, 2006, 7:24 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC