473,815 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP Array from SQL Database

10 New Member
What im attempting to do is pull email address from a database already built, i need to be able to select the email address depending on the date they are given.

Then i need to be able to Implode the list of email address so i can send out multiple emails to multiple Clients at one time. This is what i have so far.


*************** ***Form Application**** ************

<select name="emailto" size="15" multiple id="emailto" style="color: #000000; font-size: 8pt; font-family: Verdana" tabindex="">

<?php
$users_sql = "SELECT * FROM ******* WHERE site_tag = '*****' AND date_received BETWEEN '" . $_POST["startDate"] . "' AND '" . $_POST["endDate"] . "'";
$users_result = @mysql_query($u sers_sql);
while($users = @mysql_fetch_ar ray($users_resu lt))

{
echo "<option";

echo">" . $users["email"] ;
echo",</option>\n";

}

?>
</select>

*************** ***********
*************** ***********php code*********** **********

if($_POST['email_now'])
{

$to = $_POST['emailto'];
$from = "************** *";
$subject = "************** *****";
$headers .= ''************* **".$eol;
$headers .= '************** '.$eol;
$headers .= 'Return-Path: '.$eol; // these two to set reply address
$headers .= "Message-ID: <".$subject.">" .$eol;
//$headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary= md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
$body= $_POST['edited'];
//EOF;

$success = mail($to, $subject, $body, $headers);

if ($success)
{
$msg="";
mass_email($msg );


}
else
{
$msg=".";
mass_email($msg );

}
}

But what i need it to do is when i select or whoever i select from that form and click Email, it emails all of them. and i cant figure out for the life of me what im doing wrong.
Jan 10 '08 #1
13 5998
ak1dnar
1,584 Recognized Expert Top Contributor
Could you please tell us,what is NOT working in this script?
Please USE CODE tags in future.
Jan 10 '08 #2
border9
10 New Member
Its not allowing me to send to the email address the Form brings up. Right now i have it pulling about 15 email addresses from the Database and its not sending to them only one.
Jan 10 '08 #3
ak1dnar
1,584 Recognized Expert Top Contributor
Print your emails in the list menu like this: set the name attribute in this way emailto[]

Expand|Select|Wrap|Line Numbers
  1. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  2.   <option value="1@domain.com">1@domain.com</option>
  3.   <option value="2@domain.com">2@domain.com</option>
  4.   <option value="3@domain.com">3@domain.com</option>
  5. </select>
On server page
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $toArray = $_POST['emailto'];
  3. $explodedString = implode(",",$toArray);
  4. echo $explodedString;
  5. ?>

Outputs:
Expand|Select|Wrap|Line Numbers
  1. 1@domain.com,2@domain.com,3@domain.com
Pass the $explodedString to the mail() function.
Jan 10 '08 #4
border9
10 New Member
Print your emails in the list menu like this: set the name attribute in this way emailto[]

Expand|Select|Wrap|Line Numbers
  1. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  2.   <option value="1@domain.com">1@domain.com</option>
  3.   <option value="2@domain.com">2@domain.com</option>
  4.   <option value="3@domain.com">3@domain.com</option>
  5. </select>
On server page
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $toArray = $_POST['emailto'];
  3. $explodedString = implode(",",$toArray);
  4. echo $explodedString;
  5. ?>

Outputs:
Expand|Select|Wrap|Line Numbers
  1. 1@domain.com,2@domain.com,3@domain.com
Pass the $explodedString to the mail() function.
I see where your going with that, But i need to pull the emails from the database, they arent emails i put in myself. That Form is built off email address from the mySQL Database. How do i create the array from the emails in the database?
Jan 10 '08 #5
border9
10 New Member
Anyone have any idea what im trying to attempt here or what i have to do to make it work?

If you can help please by all means i would greatly appricate it. Thanks
Jan 11 '08 #6
ak1dnar
1,584 Recognized Expert Top Contributor
Oh you want to build the List menu right?
Sorry I don't have a Email Database with me, So I'm using one of my existing database.

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. @mysql_connect("localhost","root","dba")or die(mysql_error());
  3. @mysql_select_db("my_store")or die(mysql_error());
  4. $result = mysql_query("SELECT p_name from products");
  5. while($row=mysql_fetch_array($result)){
  6. $options .= '<option value="'.$row['p_name'].'">'.$row['p_name'].'</option>';
  7. }
  8. ?>
  9. <html>
  10. <body>
  11. <form action="index.php" method="post">
  12. <select name="emailto[]" multiple="MULTIPLE" id="emailto[]">
  13. <?php echo $options ?>
  14. </select>
  15. <input type="submit" name="Submit" value="Submit" />
  16. </form>
  17. </body>
  18. </html>
  19.  
Jan 11 '08 #7
border9
10 New Member
Ok, so that builds the menu, how do i take whats in that menu and email all of the clients that are brought up in that menu?

I need to be able to Click iether 1 or 20 of those items in that menu and be able to email the. Any ideas?
Jan 11 '08 #8
border9
10 New Member
[PHP]
<?php
if($_POST['email_now'])
{

$to = $_POST['emailto'];
$from = "";
$subject = "";
$headers .= "".$eol;
$headers .= "".$eol;
$headers .= 'Return-Path: '.$eol; // these two to set reply address
$headers .= "Message-ID: <".$subject.">" .$eol;
//$headers .= "Message-ID: <".$now." TheSystem@".$_S ERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion() .$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary= md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= 'Content-Type: text/html; charset=iso-8859-1'.$eol;
$body= $_POST['edited'];
//EOF;

$success = mail($to, $subject, $body, $headers);

if ($success)
{
$msg="";
mass_email($msg );


}
else
{
$msg=".";
mass_email($msg );

}
}
?>
[/PHP]

I need this code to be able to read iether 1 or multiple selections for the List that is created from the database. What i need it to do is Send out an Email to any Selected Items from that list.
Jan 12 '08 #9
border9
10 New Member
Can anyone see what im trying to acomplish here?
Jan 15 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
4313
by: James | last post by:
Hi, Have posted before, but will simplify problem here. For original post go to http://forums.devshed.com/t80025/s.html I have setup 2 arrays like so in my one page script: $carers = array( array('names' => 'Carer 01', 'hours' => 8, 'remaining' => 8),
5
4491
by: Joel Farris | last post by:
I've just finished reading Kevin Yank's book "Build Your Own Database Driven Website", and I've not quite got a handle on the array variable. Why do I need an array? Give me an example of an array in use, so that I can understand why I'd want to store a bunch of stuff in one variable. -- Joel Farris | Q: It reverses the logical flow of conversation. twinkledust Designs | A: Why is top posting frowned upon?...
4
2180
by: John Hoge | last post by:
I'm looking to make an admin page for a web photo gallery, and I need to make a drop down menu showing all files in a given directory that do not have comments in a database for the given filename. I'm curious about the most efficient way to do this. I don't want to query the database separately for each file as this would be horribly inefficient. I'm thinking about two arrays, one containing all filenames in the photo directory, and one...
23
3257
by: Rob Meade | last post by:
Lo all, Ok - this is what I was aiming to do, and then I thought - naahhh, that cant be right! query database results to recordset results to array using GetRows update values in one column in array <BOING>
0
1408
by: EMiller | last post by:
Hello, I am encountering a development challenge here that seems to be stumping me. I am developing a C#/.NET application using an MSDE database. There is a particular field in a table that I need to accept a two-dimensional array of integers. When creating the database, I chose the SQL_Variant datatype for this column to which I will be writing the array.
1
1778
by: garimapuri | last post by:
hi ihad an array in php and iwant to insert its value in database the coding is: <?php $nv_pairs = explode('&',$query_string); $array; list ($name, $value) = explode ('=',$nv_pairs); $i = 0; foreach($nv_pairs as $array) {
4
5035
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to do it? I can bind data to datagrids and lists and stuff all day long, but can't seem to grasp this one. Any pointers to a useful article / demo (or just any useful pointers!) would be much appreciated. Thanks,
7
11798
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) Your first task is to write a program which reads this file into two parallel arrays in memory. One array contains the titles, and the other array contains the authors. The arrays are 'parallel' in the sense that the n-th element of the authors...
2
15520
by: assgar | last post by:
I am having problems getting the user selected form info to inserted into the mysql database. I am also rec eving an error: Warning: Variable passed to each() is not an array or object in D:\web_server\webroot\common_list_process.php on line 1) I can display the contents of the $op array (see below) 2) Am I using the correct loop to unpact the array for inserting into the database?
5
6651
by: jmDesktop | last post by:
In my code I cannot figure out how to retrieve multple rows from my returned array from a class method. I have tried: <?php class myClass { private $connection; /* Class constructor */ function myClass(){
0
9613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10673
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10430
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6899
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3889
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3032
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.