I’m doing some simple code that doesn’t seem to be performing as expected. I am passing a single variable ‘page’ via the URL. The form is reading it, and looking into a text file. The code is taking each line of the text file and splitting it into 2 pieces, $pageName and $pageURL. I’m trying to set the variable $subject = $pageName if $page matches $pageURL. What is happening is that $subject is being set to the LAST line of the text file, no matter what $page is. I was focusing on the If statement nested within the foreach statement below, but cannot see anything wrong.
Here is the code.
[code]
$page=$_GET[‘page’];
$subject2="";
if (isset($page)){
$arr=file(“files/machines.txt”);
foreach($arr as $str) {
list($pageName,$pageURL)=explode("|",$str);
echo $pageName.", “.$pageURL.”
";
if($pageURL=$page){
$subject2=$pageName;
}
}
} [/code]
I know the text file is being read correctly because of the line echo $pageName.", ".$pageURL."<br/>";
I just put that in there to test it and will take it out once things are working. I know the page variable is being passed as well because I can echo that onto the screen.
Here is a sampling of the text file.
RW Cut-To-Length & Insulation Stripping Machine|rw
Coil Spreaders - Coil Formers|cf
Coil Winding Machines|cwm
TTT Tractor Drive Turn Taper|ttm
Any help would be appreciated.