Jump to content

Archived

This topic is now archived and is closed to further replies.

vidyashankara

Adding words into an Array

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[code]
$het = array ('HET0', 'HET1');

echo "<SELECT name='myselect'>\n";
foreach ($het as $word) {
    echo "<OPTION>$word</OPTION>\n";
}
echo "</SELECT>\n";[/code]

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.