Jump to content


Photo

Adding words into an Array


  • Please log in to reply
3 replies to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 13 June 2006 - 07:52 PM

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?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,020 posts

Posted 13 June 2006 - 07:57 PM

$het = array ('HET0', 'HET1');

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 13 June 2006 - 08:09 PM

[!--quoteo(post=383442:date=Jun 13 2006, 02:57 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Jun 13 2006, 02:57 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$het = array ('HET0', 'HET1');

echo "<SELECT name='myselect'>\n";
foreach ($het as $word) {
    echo "<OPTION>$word</OPTION>\n";
}
echo "</SELECT>\n";
[/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


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>
";




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.

#4 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 13 June 2006 - 08:37 PM

I got it! Just called it with another for function!

Thanks barand!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users