This topic is locked

Help with While loops

5/2/2019 3:48:35 PM
PHPRunner General questions
M
Melanie authorDevClub member

Sorry all - I am not a php programmer which is why I love PHPRunner, but sometimes I do want something custom. I have 3 records that I want to use in sending an e-mail when the user clicks a button (after choosing the 3 records) so on the list page I added a custom button and using the documentation I can get the e-mail to send and it includes the 3 records, but I want some data for only 1 of the records to just repeat once -
date
hotel name

address

city state zip
some wording
record 1

record 2

record 3
some more wording
so I have been trying to get it to work with another while loop but am failing. Can someone help?
My server side script for the button is:
$email_msg = "";

$email_msg.="";
$i=1;
while($data = $button->getNextSelectedRecord())

{

$x=0;

while($x<=1)

{

$email_msg.= "".$data["c_date"]."\r\n";

$email_msg.= ""."\r\n";

$email_msg.= "".$data["hotel_name"]."\r\n";

$email_msg.= "".$data["address1"]."\r\n";

$email_msg.= "".$data["city_state_zip"]."\r\n";

$email_msg.= "RE: Reservation Request"."\r\n";

$email_msg.= "We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of ".$data["rate"];

$email_msg.= "";

$email_msg.= ""."\r\n";

$x++;

}
$email_msg.= "Name: ".$data["full_emp"]."\r\n";

$email_msg.= "Check In: ".$data["check_in"]."\r\n";

$email_msg.= "Check Out: ".$data["check_out"]."\r\n";

$email_msg.= "\r\n";
}
//send email
$email = "test@test.com";
$subject = "Reservation Request";
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $email_msg));
Thank you for your time.

M
Melanie authorDevClub member 5/2/2019

OK so I am seeing now that getnextselectedrecord is not really a loop but an array? And that I don't have access to the fields ($data) outside of the {} so hmmm is there some way to do this? Can I somehow get access to the key of the first record and then grab the data to use somehow?

admin 5/2/2019

The main question here - if three records were selected, where the following is coming from?

hotel name

address

city state zip
M
Melanie authorDevClub member 5/3/2019



The main question here - if three records were selected, where the following is coming from?

hotel name

address

city state zip



Each record has that same information (joined to a master table), but I only want to include it in the e-mail one time.

admin 5/3/2019

Try something like this:

$email_msg = "";
while($data = $button->getNextSelectedRecord())

{
$email_msg.= "".$data["c_date"]."\r\n";

$email_msg.= ""."\r\n";

$email_msg.= "".$data["hotel_name"]."\r\n";

$email_msg.= "".$data["address1"]."\r\n";

$email_msg.= "".$data["city_state_zip"]."\r\n";

$email_msg.= "RE: Reservation Request"."\r\n";

$email_msg.= "We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of ".$data["rate"];

$email_msg.= "";

$email_msg.= ""."\r\n";
$email1= "Name: ".$data["full_emp"]."\r\n";

$email1.= "Check In: ".$data["check_in"]."\r\n";

$email1.= "Check Out: ".$data["check_out"]."\r\n";

$email1.= "\r\n";
}
//send email
$email = "test@test.com";

$subject = "Reservation Request";

$email_msg.=$email1;
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $email_msg));
M
Melanie authorDevClub member 5/3/2019



Try something like this:

$email_msg = "";
while($data = $button->getNextSelectedRecord())

{
$email_msg.= "".$data["c_date"]."\r\n";

$email_msg.= ""."\r\n";

$email_msg.= "".$data["hotel_name"]."\r\n";

$email_msg.= "".$data["address1"]."\r\n";

$email_msg.= "".$data["city_state_zip"]."\r\n";

$email_msg.= "RE: Reservation Request"."\r\n";

$email_msg.= "We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of ".$data["rate"];

$email_msg.= "";

$email_msg.= ""."\r\n";
$email1= "Name: ".$data["full_emp"]."\r\n";

$email1.= "Check In: ".$data["check_in"]."\r\n";

$email1.= "Check Out: ".$data["check_out"]."\r\n";

$email1.= "\r\n";
}
//send email
$email = "test@test.com";

$subject = "Reservation Request";

$email_msg.=$email1;
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $email_msg));



Closer I think with the above I got this:
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
Name: Peder, person

Check In: 05-18-2019

Check Out: 05-20-2019
So I got only 1 reservation record, but got the hotel name etc 3 times (there are 3 reservation records).

M
Mark Kramer 5/5/2019



Closer I think with the above I got this:
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
05-03-2019
Holiday Inn & Suites Hotel Bellingham
Bellingham, WA 98226
RE: Reservation Request
We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of
Name: Peder, person

Check In: 05-18-2019

Check Out: 05-20-2019
So I got only 1 reservation record, but got the hotel name etc 3 times (there are 3 reservation records).


$email_msg = "";
while($data = $button->getNextSelectedRecord())

{
$email_msg.= "".$data["c_date"]."\r\n";

$email_msg.= ""."\r\n";

$email_msg.= "".$data["hotel_name"]."\r\n";

$email_msg.= "".$data["address1"]."\r\n";

$email_msg.= "".$data["city_state_zip"]."\r\n";
$email1= "Name: ".$data["full_emp"]."\r\n";

$email1.= "Check In: ".$data["check_in"]."\r\n";

$email1.= "Check Out: ".$data["check_out"]."\r\n";

$email1.= "\r\n";
$email_msg.= "RE: Reservation Request"."\r\n";

$email_msg.= "We would like to make the following reservations on Direct Bill for the room & tax only, at the rate of ".$data["rate"];

$email_msg.= "";

$email_msg.= ""."\r\n";
}
//send email
$email = "test@test.com";

$subject = "Reservation Request";

$email_msg.=$email1;
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $email_msg));
Try rearranging the location of the name, check in, etc. like the Bold italicized above. Positioning is very important for you loop to work as desired.