Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.