oslover Posted April 18, 2008 Posted April 18, 2008 Hello. I have a conribution that exports all the emails of the subscribers to a csv file. I want it to export all the emails of the customers whose orders' status is processing because i want to notify them about their orders. Here is the code, please kindly modify it to do this job. Many thanks. <?php $filename="addresses.txt"; //.txt is good for import into excel workbook as tab delimited file // end of configuration! require('includes/application_top.php'); // gives us SOME security anyway require_once('includes/configure.php'); // gives us osC database info header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) { $sql = "SELECT customers_firstname, customers_lastname, customers_email_address "; $sql .= "FROM customers WHERE customers_newsletter = '1'"; $result = mysql_db_query ( DB_DATABASE , $sql ); echo "email\tFirst Name\tLast Name\n"; while ( $row = mysql_fetch_array($result)) { if ($row[customers_email_address]) { echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n"; } } } mysql_close (); ?>
♥Monika in Germany Posted April 18, 2008 Posted April 18, 2008 $sql = "SELECT customers_firstname, customers_lastname, customers_email_address FROM customers c, orders o WHERE c.customers_id = o.customers_id and orders_status = 2"; I can strongly recommend the phpmyadmin book by Packt Publishing ... you definitely need it for modifications like this one! :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
oslover Posted April 18, 2008 Author Posted April 18, 2008 Thank you Monika I did this if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) { $sql = "SELECT customers_firstname, customers_lastname, customers_email_address FROM customers c, orders o WHERE c.customers_id = o.customers_id and orders_status = 2"; $result = mysql_db_query ( DB_DATABASE , $sql ); echo "email\tFirst Name\tLast Name\n"; but I downloaded a txt file containing an warning error email First Name Last Name <br /> <b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/var/www/vhosts/site.com/httpdocs/admin/email_export.php</b> on line <b>37</b><br /> By the way could you please add another field (Orders ID) in an ascendent way?
♥Monika in Germany Posted April 18, 2008 Posted April 18, 2008 the original file was correct in the while section, but in the code you have right now you seem to have a mistake. You did not post that part, so I cannot tell. The query i did is correct and not the problem. As for the extra field, you need to add the column "orders_id" to the select part and the section "order by orders_id asc" before the closing " of the sql query. There are many examples similar to this in osCommerce, just open any file and you can see and borrow code from there. There is no need to reinvent the wheel :-). :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
oslover Posted April 18, 2008 Author Posted April 18, 2008 Monika Can you please look at what is missing in it, i am really a newbie :( and it's urgent :( <?php $filename="addresses.txt"; //.txt is good for import into excel workbook as tab delimited file // end of configuration! require('includes/application_top.php'); // gives us SOME security anyway require_once('includes/configure.php'); // gives us osC database info header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) { $sql = "SELECT customers_firstname, customers_lastname, customers_email_address "; $sql .= "FROM customers WHERE customers_newsletter = '1'"; $result = mysql_db_query ( DB_DATABASE , $sql ); echo "email\tFirst Name\tLast Name\n"; while ( $row = mysql_fetch_array($result)) { if ($row[customers_email_address]) { echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n"; } } } mysql_close (); ?> PLEAAAAAASE
♥Monika in Germany Posted April 18, 2008 Posted April 18, 2008 sorry, but you posted again your original file, not the new one... I may see your file if you repost tomorrow, off to bed now. :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
oslover Posted April 18, 2008 Author Posted April 18, 2008 Here is the new one. Can anyone please help, it's 6:00 am here i didn't sleep the whole night... anyone please help. <?php $filename="addresses.txt"; //.txt is good for import into excel workbook as tab delimited file // end of configuration! require('includes/application_top.php'); // gives us SOME security anyway require_once('includes/configure.php'); // gives us osC database info header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); if ( mysql_connect ( DB_SERVER , DB_SERVER_USERNAME , DB_SERVER_PASSWORD )) { $sql = "SELECT customers_firstname, customers_lastname, customers_email_address FROM customers c, orders o WHERE c.customers_id = o.customers_id and orders_status = 2"; $result = mysql_db_query ( DB_DATABASE , $sql ); echo "email\tFirst Name\tLast Name\n"; while ( $row = mysql_fetch_array($result)) { if ($row[customers_email_address]) { echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n"; } } } mysql_close (); ?>
♥Monika in Germany Posted April 19, 2008 Posted April 19, 2008 hello, use <?php $filename="addresses.txt"; //.txt is good for import into excel workbook as tab delimited file // end of configuration! require('includes/application_top.php'); // gives us SOME security anyway header('Content-Type: text/x-csv'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); $query = tep_db_query("SELECT o.orders_id, c.customers_firstname, c.customers_lastname, c.customers_email_address FROM customers c, orders o WHERE c.customers_id = o.customers_id and orders_status = 2 order by o.orders_id asc"); echo "email\tFirst Name\tLast Name\n"; while ( $row = mysql_fetch_array($query)) { if ($row[customers_email_address]) { echo "$row[customers_email_address]\t$row[customers_firstname]\t$row[customers_lastname]\n"; } } ?> :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
oslover Posted April 19, 2008 Author Posted April 19, 2008 Yeah it works :) again you proved that you are a database and mysql professional. Thank you so much Monika
StokieShinobi Posted March 28, 2011 Posted March 28, 2011 Hi all Im using this contribution too. However I want it to get all email addresses, not just those that are email subscribed. How do I change it? Is it something to do with this? $sql .= "FROM customers WHERE customers_newsletter = '1'" ; What does it need changing to to catch all email addresses? Thanks all
Recommended Posts
Archived
This topic is now archived and is closed to further replies.