Jump to content

[SOLVED] Read data from a text file


ainoy31

Recommended Posts

I would appreciate a second eye on this.  I have a text file with the following data in it:

 

1 Email [email protected],[email protected]

2 Email [email protected],[email protected]

3 Email [email protected]

1 Text [email protected],[email protected]

2 Text [email protected]

3 Text [email protected]

 

I need to go through this file and pull the data out.  Here is my code:

 

$sql = "SELECT error_id FROM error_type";
$ret = mysql_query($sql);

The sql gives me the error id in the table such as 1, 2, 3....etc.

while($row=mysql_fetch_array($ret))
{
$text = file('contactList.txt');
extract($row);
foreach($text as $line)
{
	list($error, $action, $contact) = explode(" ", $line);

	if($error == $error_id)
	{
		if($action == 'Email')
		{
			$email .= $contact;
		}
		if($action == 'Text')
		{
			$text .= $contact;
		}
	}
}

echo "Error " . $error_id . " has email addresses of: " . $email . "<br>";
echo "Error " . $error_id . " has text address of: " . $text . "<br>";

$email = "";
$text = "";
}

The output is:
Error 1 has email addresses of: [email protected],[email protected] 
Error 1 has text address of: [email protected],[email protected] 
Error 2 has email addresses of: [email protected],[email protected] 
Error 2 has text address of: [email protected] 
Error 3 has email addresses of: [email protected] 
Error 3 has text address of: [email protected] 

The email address output is correct but why I am getting [email protected],[email protected] for my text addresses.  It should be the same as the email listings.  Hope this is clear enough.  Much appreciation.  AM

Link to comment
https://forums.phpfreaks.com/topic/154931-solved-read-data-from-a-text-file/
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.