Page 1 of 1

Limit fields sent by email

Posted: 2013-09-11 20:39
by benzoD
I've successfully used the email code from the tutorial to have emails sent to a user when inserting records. The issue I'm having is that I don't want all of the fields in the table to be sent, as some are simply for internal use and I'd like for it to be as uncluttered as possible.

The code I'm working with is this:

Code: Select all

         foreach($data as $field => $value){
                $messageData .= "$field: $value \n";
I know that the foreach is looping through the object to display every field contained within and assigning it to $message data, but I'd like to have only 5 of the 10 fields sent. How do I get only certain parts of the $data to be displayed in my emails?

Re: Limit fields sent by email

Posted: 2013-10-14 01:19
by a.gneady
Try this:

Code: Select all

$fields_to_send = array('field1', 'field3', 'field5');
foreach($fields_to_send as $field){
    $messageData .= "$field: {$data[$field]} \n";
So, instead of looping on $data which sends all fields, you're looping only on the fields specified in $fields_to_send

Re: Limit fields sent by email

Posted: 2013-11-04 14:17
by benzoD
Just seeing this now, but I will give it a try and report back. Thanks for the reply!

Re: Limit fields sent by email

Posted: 2014-02-17 15:50
by benzoD
Just confirming that this works well!

Re: Limit fields sent by email

Posted: 2014-04-28 17:22
by toconnell
OK.. I want to do the same thing but I want to show a 'look up field' without just the record number.. so I need to do an inner join on one of the fields.. How do I make sure I can show the actual look up value and not the record ID that shoes.. in this situation?

For example.. county 5 is Brevard.. I want the message data to show Brevard, not the 5 that shows now. So using this code above, where do I put the inner join of the table to pull the actual data out?

Thanks,

Re: Limit fields sent by email

Posted: 2014-04-28 23:31
by peebee
You could try LEFT JOIN - ref: http://www.w3schools.com/sql/sql_join_left.asp

Whilst I have no idea what your table and field names are, you can hopefully get the general idea by fiddling around with this guesswork example below......

$county=sqlValue("select c.countyID from routes r left join countys c on c.id=r.countyref where yourprimkey='".makeSafe($selected_id)."'");

then....

$messageData .= "County: $county" \n;

Hopefully that will work for you.