Jump to content

Having a little problem


Schlo_50

Recommended Posts

Hi all,

 

I am having a problem with a certain hidden field. This hidden field needs to hold the value $name, but I don't want it to be inside my foreach loop. However, If I have it outside of my foreach loop the variable $name isn't assigned the value it is meant to. Im not sure how else to explain this, so my code is as follows. It should become clearer when you see the commented line I have included.

 

print "<select name=\"manufacturer\" class=\"form\">";
print "<option value=\"none\" selected=\"selected\">Not Applicable</option>";

$linesb = file("data/manufacturers.DAT");
foreach ($linesb as $lineb) { 
$datab = explode("|", $lineb);

$mid = trim($datab[0]);
$name = trim($datab[1]);   
  
print "<option value=\"$mid\">$name</option>";
}
// $name below takes on the last value in my .DAT list because it is outside of the loop.
print "<input type=\"hidden\" name=\"manhide\" value=\"$name\" class=\"form\">";
print "</select>";

 

Thanks in advance guys!

Link to comment
https://forums.phpfreaks.com/topic/107776-having-a-little-problem/
Share on other sites

Archived

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

×
×
  • Create New...

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.