Forums / General Questions / Querying db for more info to add to confirmation email

Querying db for more info to add to confirmation email

Locked

Started by mygreygoose on 14 Dec 2007, 12:25 AM · Views: 913

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
14 Dec 2007, 12:25 AM
#1
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Querying db for more info to add to confirmation email

I'm querying the db to add more detail to the order confirmation email. I'm only adding it to the admin "extra_info" email. I have the includes/functions/functions_email.php part working:

   function email_collect_extra_info($from, $email_from, $login, $login_email, $login_phone='', $login_fax='', $login_heard_from='', $login_heard_from_other='') {

 ... 
 
 // generate footer details for "also-send-to" emails.  Pulls data from includes\classes\order.php
        $extra_info=array();
    $extra_info['TEXT'] =
      OFFICE_USE . "\t" . "\n" .
      (trim($login) !='' ? OFFICE_LOGIN_NAME . "\t\t" . $login . "\n"  : '') .
      (trim($login_email) !='' ? OFFICE_LOGIN_EMAIL . "\t\t" . $login_email . "\n"  : '') .
      ($login_phone !='' ? OFFICE_LOGIN_PHONE . "\t\t" . $login_phone . "\n" : '') .
      ($login_fax !='' ? OFFICE_LOGIN_FAX . "\t\t" . $login_fax . "\n" : '') .
      (trim($login_heard_from) !='' ? OFFICE_LOGIN_HEARD_FROM . "\t\t" . $login_heard_from . "\n" : '') .
      (trim($login_heard_from_other) !='' ? OFFICE_LOGIN_HEARD_FROM_OTHER . "\t" . $login_heard_from_other . "\n" : '') . "\n\n";  
```but I can't get the data I need to pass into it working in includes/classes/order.php.  I'm sure it has to do with how my novice php skills are not getting the sql & php info right.  This is what I've added into order.php:

```php
    $heard_from_query = "SELECT orders.orders_id, sources.sources_name, sources_other.sources_other_name FROM (((customers LEFT JOIN customers_info ON customers.customers_id = customers_info.customers_info_id) LEFT JOIN sources_other ON customers_info.customers_info_id = sources_other.customers_id) LEFT JOIN sources ON customers_info.customers_info_source_id = sources.sources_id) INNER JOIN orders ON customers.customers_id = orders.customers_id 
                         where orders_id = '" . (int)$order_id . "'";      

    $heard_from = $db->Execute($heard_from_query);  
```and

```php
    // send additional emails
    if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
      $extra_info=email_collect_extra_info('','', $this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], $this->customer['telephone'], '', $heard_from->fields['sources_name'], $heard_from->fields['sources_other_name']);  
      $html_msg['EXTRA_INFO'] = $extra_info['HTML'];
            
      if ($GLOBALS[$_SESSION['payment']]->auth_code || $GLOBALS[$_SESSION['payment']]->transaction_id) {
        $pmt_details = 'AuthCode:  ' . $GLOBALS[$_SESSION['payment']]->auth_code . "\n" . 'TransID:  ' . $GLOBALS[$_SESSION['payment']]->transaction_id . "\n\n";
        $html_msg['EMAIL_TEXT_HEADER'] = nl2br($pmt_details) . $html_msg['EMAIL_TEXT_HEADER'];
      }

      zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, SEND_EXTRA_NEW_ORDERS_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
      $email_order . $extra_info['TEXT'] . $pmt_details, STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra'); 
    }
```Basically, I need to pass sources_name and sources_other_name into the email_collect_extra_info function.  What am I doing wrong?
17 Dec 2007, 12:12 AM
#2
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Re: Querying db for more info to add to confirmation email

I need to clarify this question in order to make it simpler to answer. I have a mysql query that generates one row of data. I'm trying to then pass one of the field's value into a function.

Basically, how do I get use PHP to capture that value? Since the value is in an array, I don't know how to reference that.

18 Dec 2007, 4:05 AM
#3
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Re: Querying db for more info to add to confirmation email

I've tried everything, and I cannot figure out how to get this to work. In includes/classes/order.php, I am trying every possible combination of something like:

function send_order_email($zf_insert_id, $zf_mode) {
global $currencies, $order_totals;

$sql_command="SELECT orders.orders_id, sources.sources_name, sources_other.sources_other_name
FROM (((customers LEFT JOIN customers_info ON customers.customers_id = customers_info.customers_info_id) LEFT JOIN sources_other ON customers_info.customers_info_id = sources_other.customers_id) LEFT JOIN sources ON customers_info.customers_info_source_id = sources.sources_id) INNER JOIN orders ON customers.customers_id = orders.customers_id
WHERE orders_id = '" . (int)$order_id . "'";

$rs_list=mysql_query($sql_command);
$list=mysql_fetch_assoc($rs_list);

... etc ...

$extra_info=email_collect_extra_info('','', $this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], $this->customer['telephone'], '', $list['sources_name'], $list['sources_other_name']);

But I always get null for the value of $list['sources_name'] and $list['sources_other_name'].

The biggest problem is that I don't know how to test whether I have my sql / php statement correct b/c this is in a class... and I can't test it on screen.

HELP!!!!!!!

18 Dec 2007, 4:25 AM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Querying db for more info to add to confirmation email

MyGreyGoose:

The biggest problem is that I don't know how to test whether I have my sql / php statement correct b/c this is in a class... and I can't test it on screen.You could always test the SQL query via phpMyAdmin ...

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Dec 2007, 4:29 AM
#5
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Re: Querying db for more info to add to confirmation email

The SQL query works in mysql browser. Which is why I'm thinking it has something to do with my PHP related to getting the data from the sql query... maybe the WHERE orders_id = '" . (int)$order_id . "'" isn't right?

18 Dec 2007, 4:36 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Querying db for more info to add to confirmation email

MyGreyGoose:

maybe the WHERE orders_id = '" . (int)$order_id . "'" isn't right?

No, that looks fine, syntax-wise.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Dec 2007, 4:40 AM
#7
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Re: Querying db for more info to add to confirmation email

In includes/classes/order.php, there are bunch of functions. Does it matter where I place that code? As in, should go within the function I'm using, or outside. Do I need to declare some variables or something?

18 Dec 2007, 4:49 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: Querying db for more info to add to confirmation email

Actually ... shouldn't it be $zf_insert_id instead of $order_id

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Dec 2007, 5:20 AM
#9
mygreygoose avatar

mygreygoose

New Zenner

Join Date:
Jun 2007
Posts:
91
Plugin Contributions:
0

Re: Querying db for more info to add to confirmation email

YESSSSS!!!!!!! Thank you!!! I was literally pulling my hair out.

But I don't understand why it was that when there were numerous instances of where orders_id = '" . (int)$order_id . "' throughout that file. No need for an explanation... I'm just ecstatic I got it to work after days of trying.