Hello everyone,
I m a little stuck with a problem here. How do I email a message to all the email addresses in my Mysql database? I believe I need to use arrays but I am not very familiar with them. Please help.:blush:
Printable View
Hello everyone,
I m a little stuck with a problem here. How do I email a message to all the email addresses in my Mysql database? I believe I need to use arrays but I am not very familiar with them. Please help.:blush:
Have you been able to retreive data from your database?
What have you got so far?
Yes I have managed to get info from the database and echo it. I've also managed to update it and delete it. I know how to send mail to an address inthe code but I don't know much about arrays amd iteration ..I know I should use one of or a combination of the two...but how.
CODE:
:confused:Code:<?php
//SQLUtils contains all the details of the database connection
require_once('SQL_Utils1.php');
//connect to the database
$dbConn = getDatabaseConnection();
if($query = "SELECT * FROM Mail_List") {
//if query does run print message
echo "done ";
//otherwise if query does not run print message
}else{
echo 'Problem';
echo '<br>';
}
//this is a bit of borowed code which didn t work
while($row = mysql_fetch_array($query)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
}
$result = runQuery($query, $dbConn);
//end connection to db
disconnectFromDatabase($dbConn);
?>
This line:
does not execute anything. What that statement does is assign the query text to the $query variable, and then test whether it can be evaluated to true or not, which it can because anything that isn't false or null is true. So it will always return true.Quote:
Originally Posted by stephanief
What you need to do, presumably, is this:
Assuming1 that $result is a MySQL resultset resource, you can then do this (in the "it worked" part):PHP Code:$dbConn = getDatabaseConnection();
$query = "SELECT * FROM Mail_List";
if ($result = runQuery($query, $dbConn)) {
// it worked
}
else {
// it didn't
}
In each iteration, $row will point to an array containing the field values. Use mail() to send an email.PHP Code:while ($row = mysql_fetch_assoc($result)) {
// magic here
}
1. I can't help any more than that at this point, as I am not aware of your database schema or how the SQL_Utils1.php script works.
Solved the problem thank you just needed a little push.
Thanks LOTS :)
You're very welcome and now that the problem is solved we would appreciate it if you could help us out by marking it as such using the Thread Tools menu above the first post. :)