pakenney38 Posted February 5, 2008 Share Posted February 5, 2008 I really don't know how to explain this, but I have a Tab-delimited file that I want to read line-by-line. In a line is an employee number. I want to get the lastname and firstname of the employee from a MySQL table using the employee number as the relative key. I want to do this for each line then display the results on the screen. The problem is that the script gets the firstname and lastname of the employees until it hits an employee that is not in the MySQL table, then it fails to get the firstname and lastname for the remainder of the employees, even if some of them are in the MySQL table. Here is my example: <?PHP $host = "XXX"; $user = "XXX"; $pwd = "XXX"; $filename = "C:\aaron.csv"; $fh = fopen($filename, 'r'); $theData = fread($fh, filesize($filename)); fclose($fh); $line = explode("\r\n", $theData); mysql_connect($host, $user, $pwd); mysql_select_db("database") or die("Error: " . mysql_error()); foreach ($line as $key => $value) { $info = explode("\t", $value); $info[1] = trim($info[1]); $empno = $info[1]; echo $info [1]; echo "<br>"; echo $empno; echo "<br>"; $query = "SELECT lastname, firstname FROM name WHERE empnumber = '$empno'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $lastname = $row['lastname']; $firstname = $row['firstname']; echo $row['lastname']; echo "<br>"; echo $lastname; echo "<br>"; echo $row['firstname']; echo "<br>"; echo $firstname; echo "<br><br>"; } mysql_close(); ?> Any help would be great thank you. This is driving me nuts. Quote Link to comment Share on other sites More sharing options...
Moon-Man.net Posted February 5, 2008 Share Posted February 5, 2008 I may be wrong, but try changing these two lines foreach ($line as $key => $value) { $info = explode("\t", $value); to oreach ($line as $single_line) { $info = explode("\t", $single_line); Maybe add a few debug echo's around the joint to see whats happening Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted February 6, 2008 Author Share Posted February 6, 2008 Thanks, but that's the way it was originally and it produced the same effect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.