vidyashankara Posted June 13, 2006 Share Posted June 13, 2006 I have an Array, $het, which contains 2 words -> HET0 and HET1 I tried to get these words into a drop down box in HTML, But PHP creates 2 drop down boxes. How do i get all the words in a array to fall in the dropdown list? I thought i insert the words again into an array and call it with an for function... would that work? any ideas? Link to comment https://forums.phpfreaks.com/topic/11912-adding-words-into-an-array/ Share on other sites More sharing options...
Barand Posted June 13, 2006 Share Posted June 13, 2006 [code]$het = array ('HET0', 'HET1');echo "<SELECT name='myselect'>\n";foreach ($het as $word) { echo "<OPTION>$word</OPTION>\n";}echo "</SELECT>\n";[/code] Link to comment https://forums.phpfreaks.com/topic/11912-adding-words-into-an-array/#findComment-45192 Share on other sites More sharing options...
vidyashankara Posted June 13, 2006 Author Share Posted June 13, 2006 [!--quoteo(post=383442:date=Jun 13 2006, 02:57 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 13 2006, 02:57 PM) [snapback]383442[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$het = array ('HET0', 'HET1');echo "<SELECT name='myselect'>\n";foreach ($het as $word) { echo "<OPTION>$word</OPTION>\n";}echo "</SELECT>\n";[/code][/quote]$het is dynamic, Depending on the text file, It can HET0, HET1, HET2 or just HET0. Here's the code so that you can understand my position better[code]foreach($input as $line) { $line[0] = 'A'; $line[1] = 'T'; $line[2] = 'O'; $line[3] = 'M'; $line[4] = ' '; $line[5] = ' '; $line[72] = 'H'; $line[73] = 'E'; $line[74] = 'T'; $line[75] = $i; f write($fp,$line);}$segid = "$line[72]$line[73]$line[74]$line[75]";f write($fp,$end);f close($fp);echo "<input type=checkbox name=het[] value='$het[$i]|$segid' checked><a href='${id}_het_$hetsmall.pdb'>${id}_het_$hetsmall.pdb </a> SEGID : $segid<br>";}echo "<br>You can select Residues that you may want to protonate<br><p><select name=resi><option value=ASP>ASP<option value=GLU>GLU</select>Residue ID <input type=text name='resid'><select name=segid> ";foreach($segid as $seg) {echo "<option value=$segid>$seg";}echo "</select><br>";[/code]I cant put the Drop down box inside the foreach function, It creates 2 Drop down boxes. If i put it outside the function, Only the last value of $segid shows up. What do i do?by the way $line[72,73,74,75] are the columns of a text file. Link to comment https://forums.phpfreaks.com/topic/11912-adding-words-into-an-array/#findComment-45195 Share on other sites More sharing options...
vidyashankara Posted June 13, 2006 Author Share Posted June 13, 2006 I got it! Just called it with another for function! Thanks barand! Link to comment https://forums.phpfreaks.com/topic/11912-adding-words-into-an-array/#findComment-45207 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.