Help Array and File
<p>Very new to PHP and ran into some trouble and was wondering if anyone could help. I'm having problems with an array of names that are looked up in a database. When I use just the array of names it gets processed correctly. When I try and read a file of those same names only the last name gets displayed. My question is how can I get all names displayed for the file array?</p>

<p>Please see examples and code below. Thanks for your time.</p>

<p>//This works -- Sample 1</p>

<p>$x=array("joe", "paul", "tom");</p>

<p>//This does not -- Sample 2</p>

<p>$x = file("name.txt"); //Same names from the array above are in this file</p>

<p>Here is the full code below.</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Name Check&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;?php

$con = mysql_connect("localhost","xxxxxxxx","xxxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxxxxxxx", $con);


//$x=array("joe", "paul", "tom");       //displays all names correctly in Sample 1 below
$x = file("name.txt");                    //only displays the last name in the file. Sample 2 below

foreach ($x as $test) {
$result = mysql_query("SELECT * FROM categories WHERE Name='$test' Limit 0, 1");

while($row = mysql_fetch_array($result))
  {
  echo $row['Name'];
  echo " " . $row['Sport'];
  echo "&lt;br /&gt;";
  }
  }
?&gt; 
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<hr>

<p><strong>Sample 1 output</strong></p>

<p>joe basketball</p>

<p>paul basketball</p>

<p>tom baseball</p>

<p><strong>Sample 2 output</strong></p>

<p>tom baseball</p>

<hr>

<p>Here is the contents of name.txt, that was requested. Thanks!</p>

<pre><code>joe 
paul 
tom
</code></pre>
