alright i have a system where im pulling all of the emails from part of my database into the mail function so that i may email all of the addresses at once. Heres the problem some of the agents in my database do not have email address's so as a result...the email field is blank (duh) so, i want my query which pulls up all the emails from the database, to exlude any empty fields. Whats the best way to do this? or should i do it in php? please help! thanks in advance!
Filter out empty search results from a database
Started by kyleblackman, Oct 13 2006 11:29 AM
6 replies to this topic
#1
Posted 13 October 2006 - 11:29 AM
#2
Posted 13 October 2006 - 12:28 PM
adam127, on Oct 13 2006, 06:24 PM, said:
You could use PHP and SQL.
Heres an example:
Something like that will work
- Adam
Heres an example:
<?php
$get = mysql_query("SELECT * FROM `table`") or die(mysql_error());
while($x = mysql_fetch_array($get))
{
if(strlen($x['email'] < 0)){
echo $x['email'] . "<br />";
}
}
?>
Something like that will work
- Adam
Don't you mean...
if(!strlen($x['email'] > 0)){orif(strlen($x['email'] < 1)){
Edited by Matthew., 13 October 2006 - 12:28 PM.
#3
Posted 13 October 2006 - 12:30 PM
okay cool adam. this is in reguards to the same thing you helped me out with the other day. so could you show me exactly where i should place this?
heres the code:
$getemails = mysql_query("SELECT email FROM `lag` WHERE category LIKE'%$cat%' AND state LIKE '%$stateID%'") or die(mysql_error());
while($user= mysql_fetch_array($getemails))
{
$to = $user['email'];
$from = "$from";
$subject = "$querytitle";
$message = "$message";
$headers ="From: $from \n";
$headers .="Reply-To: $from";
mail($to,$subject,$message,$headers);
};
thank you much adam. youre a life saver.
heres the code:
$getemails = mysql_query("SELECT email FROM `lag` WHERE category LIKE'%$cat%' AND state LIKE '%$stateID%'") or die(mysql_error());
while($user= mysql_fetch_array($getemails))
{
$to = $user['email'];
$from = "$from";
$subject = "$querytitle";
$message = "$message";
$headers ="From: $from \n";
$headers .="Reply-To: $from";
mail($to,$subject,$message,$headers);
};
thank you much adam. youre a life saver.
#4
Posted 13 October 2006 - 12:58 PM
ahh man im sorry for bein kinda dumb on this stuff. i need to make absolutly certain where things go because i know how picky this kinda code is. and im glad i asked because i was going to place it earlier in the code.
so i appologize. and just to be clear, this will still send emails even if there are empty ones in the query result right? its just going to leave out the empty results?
so i appologize. and just to be clear, this will still send emails even if there are empty ones in the query result right? its just going to leave out the empty results?
Edited by kyleblackman, 13 October 2006 - 01:00 PM.
#5
Posted 13 October 2006 - 01:11 PM
hmm. it seems to still be printing the empty results too. i took out the mail function and did this
if(strlen($to < 1)){
echo "$to<br>";
};
and on the results page, its like this
email@domain.com
email@domain.com
email@domain.com
email@domain.com
with the empty spaces obviously indicatiing its pulling up an empty row. i wish this wasnt such a bitch! if theres empty rows and i try to send an email, i get an internal server error.
if(strlen($to < 1)){
echo "$to<br>";
};
and on the results page, its like this
email@domain.com
email@domain.com
email@domain.com
email@domain.com
with the empty spaces obviously indicatiing its pulling up an empty row. i wish this wasnt such a bitch! if theres empty rows and i try to send an email, i get an internal server error.
#6
Posted 13 October 2006 - 01:31 PM
nevermind, i found the solution. but its just too many emails haha. my server wont handle it. wow thats alot of work for nothing.
#7
Posted 13 October 2006 - 03:31 PM
Try to moderate your massive emailing, lol.
Personally, I would have let the MySQL query do all the filtering work for me.
Don't see the point in your odd way of assigning variables either, lol. '$message = "$message"'. Really???
Personally, I would have let the MySQL query do all the filtering work for me.
$getemails = mysql_query("SELECT `email` FROM `lag` WHERE `email` != '' AND `category` LIKE'%$cat%' AND `state` LIKE '%$stateID%'") or die(mysql_error());
while($user= mysql_fetch_array($getemails))
{
$to = $user['email'];
$subject = $querytitle;
$headers ="From: $from \nReply-To: $from";
mail($to,$subject,$message,$headers);
};
Don't see the point in your odd way of assigning variables either, lol. '$message = "$message"'. Really???
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
