Link to home
Start Free TrialLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP loop and GET

<?php 
        $query6 = $conn->prepare("SELECT sup_contact, radnew FROM support WHERE sup_contact = 'Bill' AND radnew='New Ticket' ");
        $query6->execute();
        $results6 = $query6->get_result();
     $row_cnt6 = $results6->num_rows;
        ?>

Open in new window

The above code works but I need to be able to use the code to return a row count for radnew='In Progress', radnew='Closed' and radnew='No Category' as some sort of loop rather than writing it out 3 more times for the other variables


Also, is it possible to use this:
$variablename = $_GET['variable1'].$_GET['variable2'].etc
As a string
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

You can use a parameter in the query and then loop through the various values to execute it:

Something like this maybe:

$query = $conn->prepare("SELECT sup_contact, radnew FROM support WHERE sup_contact = 'Bill' AND radnew = ? ");
$query->bind_param('s', $radnew);

$values = array('In Progress', 'Closed', 'No Category');

foreach ($values as $radnew):
    $query->execute();
    $results = $query->get_result();
    echo $results->num_rows;
endforeach;

Open in new window

And yes. This is possible:

$variablename = $_GET['variable1'].$_GET['variable2'];
Avatar of doctorbill

ASKER

Fantastic - one thing. How would I echo out the $results for each row as a variable list
Also, is it possible to use this:
$variablename = $_GET['variable1'].$_GET['variable2'].etc
As a string
Yes but not advisable - you cannot guarantee that the $_GET variables exist.

Always better to be neat and robust than concise when it comes to code.
So
$variablename = isset($_GET['variable1]) ? $_GET['variable1] : '';
$variablename .= isset($_GET['variable2]) ? $_GET['variable2] : '';
...

Open in new window

This ensures that your script does not crash - it is a bit more verbose but it is also clearer what you are doing.
There are no prizes for how much code you can write on one line. In the above example we could write it like this as well (following the above rule to the nth degree)
$variablename = isset($_GET['variable1]) 
    ? $_GET['variable1] 
    : '';

Open in new window

It is possible to be too verbose as well. Nothing wrong with the above - it comes down to personal preference.
Rule of thumb: as soon as you have to start using your (mental) fingers to keep track of what a line (or block) of code is doing - time to reformat it.

Regarding the query - if you don't need the sup_contact but just the counts you can do that with a query
SELECT COUNT(*), `radnew` 
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('closed','in progress','no category') 
GROUP BY `radnew`

Open in new window

Given you are filtering by sup_contact anyway you don't need it in the projected values and you can use the DB to do the row counts for you.
Message for Chris:
$query = $conn->prepare("SELECT sup_contact, radnew FROM support WHERE sup_contact = 'Bill' AND radnew = ? ");
$query->bind_param('s', $radnew);

$values = array('In Progress', 'Closed', 'No Category');

foreach ($values as $radnew):
    $query->execute();
    $results = $query->get_result();
    echo $results->num_rows;
endforeach;

Open in new window

Message for Chris:
Can you tell me how to integrate your code (below) with the code above so that it will echo out the results as named variables so I can use the values elsewhere on the page. I only need the row count results:
SELECT COUNT(*), `radnew` 
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('closed','in progress','no category') 
GROUP BY `radnew`

Open in new window

Two messages for Chris - I am assuming the second was for me - if not I will answer it anyway.

$query = <<< QUERY
SELECT COUNT(*) AS `total`, `radnew` 
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('closed','in progress','no category') 
GROUP BY `radnew`
QUERY;
$stmt = $conn->prepare($query);
$stmt->execute();
echo "<table>";
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  echo <<< ROW
  <tr>
    <td>Bill</td>
    <td>{$row['radnew']}</td>
    <td>{$row['total']}</td>
  </tr>
ROW;
}
echo "</table>";

Open in new window

There area couple of ways you can do this. If you're going with the GROUP BY, then you'll probably want to fetch all so you have an array of the results:

$query = $db->query("SELECT COUNT(1), `radnew` FROM `support` WHERE `sup_contact` = 'Bill' AND `radnew` IN ('closed','in progress','no category') GROUP BY `radnew`");
$results = $query->fetch_all();
var_dump($results);

Open in new window

The $results variable is now an array containing 3 entries - each entry will contain the radnew value and the count.

Alternatively, you can build your own array for the results. This way will give you a cleaner array as the result:

$query = $db->prepare("SELECT COUNT(1) FROM `support` WHERE `sup_contact` = 'Bill' AND `radnew` = ?");
$values = array('In Progress', 'Closed', 'No Category');

$query->bind_param('s', $radnew);
$query->bind_result($count);

foreach ($values as $radnew):
    $query->execute();
    $query->fetch();
    $results[$radnew] = $count;
endforeach;

Open in new window

Again, the $results variable will contain an array - the key is the radnew and the value is the row count:

array('In Progress' => 4, 'Closed' => 7, 'No Category' => 12)
Will try both solutions and get back to you - thanks for such a rapid response
Really appreciated
First test:
When I use this code:

 <?php 
       $query = <<< QUERY
SELECT COUNT(*) AS `total`, `radnew` 
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('closed','in progress','no category') 
GROUP BY `radnew`
QUERY;
$stmt = $conn->prepare($query);
$stmt->execute();
echo "<table>";
$result = $stmt->get_result();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  echo <<< ROW
  <tr>
    <td>Bill</td>
    <td>{$row['radnew']}</td>
    <td>{$row['total']}</td>
  </tr>
ROW;
}
echo "</table>";
        ?>

Open in new window

I get the following (see attached)
rather than just one line:
Bill    Closed   In Progress   No Category
          7            2                     2
Capture.PNG
When I use this code (I changed the $db to $conn):

 <?php 
      $query = $conn->prepare("SELECT COUNT(1) FROM `support` WHERE `sup_contact` = 'Bill' AND `radnew` = ?");
$values = array('In Progress', 'Closed', 'No Category');

$query->bind_param('s', $radnew);
$query->bind_result($count);

foreach ($values as $radnew):
    $query->execute();
    $query->fetch();
    $results[$radnew] = $count;
endforeach;
        ?>

Open in new window

I get this:
Fatal error: Cannot use object of type mysqli_result as array in C:\xampp\htdocs\Development\Inventas\Sites\TicketStatus_AllStatusSearchMetrics.php on line 130

This refers to this line: $results[$radnew] = $count;
Hmmm. Maybe something else is going on - I've just tested both the code snippets and they work exactly as they should.

Is there some other code that you're not showing us ?
Now working - I had a loop within a loop so I have cleaned up the page and removed unused code
Both solutions now work
 <?php 
     $query = <<< QUERY
SELECT COUNT(*) AS `total`, `radnew` 
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('new ticket','in progress','closed','no category') 
GROUP BY `radnew`
QUERY;
$stmt = $conn->prepare($query);
$stmt->execute();
echo "<table>";
$result = $stmt->get_result();
       
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  echo <<< ROW
 
    <td>Bill</td>
    <td>{$row['radnew']}</td>
    <td>{$row['total']}</td>
  
ROW;
    
}
echo "</table>";

Open in new window

Finally
How do I change the order to New Ticket, In Progress, Closed and No category and reference the values so I can send in a form. ie add names to the <td> tags for each value
Sorry - forgot to attach file for the above:
Capture.PNG
Good stuff.

To set the order, you have a couple of options. Probably the easiest is to use the first code snippet (loop over an array of values and execute the query each time). The final result will already be in the order of your $values array, so just looping over them for output will keep the correct order.

The other alternative is to add in a generated column to your query that you can then use to sort the output (you'd want to use the CASE keyword!).

As for the form, you can add in whatever html you want when you generate your TD. If you want to send inputs then something like:

<td>Bill</td>
<td>{$row['radnew']}</td>
<td><input type="text" name="values[{$row['radnew']}]" value="{$row['total']}" /></td>

That would generate an array of inputs that can be looped through when you submit the form.

foreach ($_POST['values'] as $radnew => $value):
    echo $radnew;
    echo $value;
endforeach;
sorry which was  "use the first code snippet"
I am trying this:
The other alternative is to add in a generated column to your query that you can then use to sort the output (you'd want to use the CASE keyword!).

Code:
GROUP BY `radnew` ORDER BY 'radnew' ASC

It does not arrange the names in the order needed - alphabetical. How is the CASE used
The first code snipped was this one:

$query = $db->prepare("SELECT COUNT(1) FROM `support` WHERE `sup_contact` = 'Bill' AND `radnew` = ?");
$values = array('In Progress', 'Closed', 'No Category');

$query->bind_param('s', $radnew);
$query->bind_result($count);

foreach ($values as $radnew):
    $query->execute();
    $query->fetch();
    $results[$radnew] = $count;
endforeach;

Open in new window

As for using CASE, you'd do something like this:

SELECT COUNT(*) AS `total`, `radnew`
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('new ticket','in progress','closed','no category') 
GROUP BY `radnew`
ORDER BY
   CASE `radnew`
      WHEN 'new ticket' THEN 0
      WHEN 'in progress' THEN 1
      WHEN 'closed' THEN 2
      WHEN 'no category' THEN 3
   END

Open in new window

Basically, it converts the values from radnew into 0,1,2,3 which is then used to sort on
Is it supposed to be sorting on the names - new ticket, in progress etc
It just doesn't do it
do the count values have any effect on this

example:
<?php 
     $query = <<< QUERY
SELECT COUNT(*) AS `total`, `radnew`
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('new ticket','in progress','closed','no category') 
GROUP BY `radnew`
ORDER BY 
CASE 'radnew'
      WHEN 'New Ticket' THEN 0
      WHEN 'In Progress' THEN 1
      WHEN 'Closed' THEN 2
      WHEN 'No Category' THEN 3
   END
QUERY;
$stmt = $conn->prepare($query);
$stmt->execute();
echo "<table>";
$result = $stmt->get_result();
       
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  echo <<< ROW
 <tr>
    <td>Bill</td>
    <td>{$row['radnew']}</td>
    <td>{$row['total']}</td>
  </tr>
ROW;
    
}
echo "</table>";
        ?>

Open in new window


This gives the following (attached file)
Capture.PNG
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perfect
WELL SPOTTED
Another option is to create a radnew lookup table (radnew_lookup)
order radnew
1     New Ticket
2     In Progress
3     Cloesd
4     No Category

Open in new window

Then join your query to this table and do the ordering on the first column
SELECT COUNT(*) AS `total`, `radnew`
FROM `support` s LEFT JOIN `radnew_lookup` rrl ON s.radnew = rl.radnew
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('new ticket','in progress','closed','no category') 
GROUP BY `radnew`
ORDER BY 
   rl.order

Open in new window

And then make sure this an index on the radnew column in both tables.
<form id="formSend" name="formSend" method="POST" action="emailedforms/status_emails.php">

 <?php foreach ($_POST['values'] as $radnew => $value):
    echo $radnew;
    echo $value;
endforeach;   ?>    
</form>

Open in new window

I am obviously doing something wrong here. This code gives me an error when I submit the form:
"Notice: Undefined index: values in C:\xampp\htdocs\Development\Inventas\Sites\TicketStatus_AllStatusSearchMetrics.php on line 153
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\Development\Inventas\Sites\TicketStatus_AllStatusSearchMetrics.php on line 153"
The error refers to "<?php foreach ($_POST['values'] as $radnew => $value):"

I have added the code for the <td>tag in the script above:
<td> <input type="text" name="values[{$row['radnew']}]" value="{$row['total']}" />{$row['total']}</td>
I thought that as the 'values' has been defined previously  the loop would be able to pick it up
I have the order issue sorted now but the form problem still remains. How to send the data from this code:

https://www.experts-exchange.com/questions/29133098/PHP-loop-and-GET.html?anchorAnswerId=42783584#a42783584
What I am trying to do is to send these values from the form to the "emailedforms/status_emails.php" page as variables
You can only access the POST array once you've posted a form, so I'm guessing the form and the inputs goes in the same script as your DB query. In that page, you also have the form that POSTs to the status_emails.php page, and then in that script you can loop through the POST array to get the values.

So in your DB script, you'd have something like this:

$stmt = $conn->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
       
echo "<form id='formSend' name='formSend' method='POST' action='emailedforms/status_emails.php'>";
echo "<table>";

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
echo <<< ROW
    <tr>
        <td>Bill</td>
        <td>{$row['radnew']}</td>
        <td><input type="text" name="values[{$row['radnew']}]" value="{$row['total']}"</td>
    </tr>
ROW;   
}

echo "</table>";
echo "<input type='submit' name='submit' value='Go'>";
echo "</form>";

Open in new window

That will generate a form from your DB values and include text inputs containing the values from the total column. When you click on the Go button, the form will be POSTed to the status_emails.php script where you can loop over the values array:

foreach ($_POST['values'] as $radnew => $total):
    echo $radnew;
    echo $total;
endforeach;

Open in new window

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

//require_once 'incSearchDatabaseConnectionBySelection.php';

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$hostname = 'localhost';
$username = 'root';
$password = '***********';
$database = 'inventas';

try {
    $conn = new mysqli($hostname, $username, $password, $database);
}
catch (Exception $e)
{
    die("Could not connect to the DB");
    
    $break= "<br>";
}

 $break= "<br>";
?>



<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Inventas Sites Visits</title> 
    
       
        <link rel="stylesheet" type="text/css" href="css/styleTable_metrics.css">
        <link href="css/menu.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" type="text/css" href="css/style_metrics.css">
    <link href="css/layout_metrics.css" rel="stylesheet" type="text/css" />
       
        
         <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        
    </head>
    <body>
        
        
<div class="menudivalign"><?php require_once('incMenu.php'); ?></div><br /><br />
       <div class = "pageheading"><h1>Ticket Status - All Tickets</h1></div><br /> 
        
        
       
        
        <div><span style = "margin-left:50px; font-weight: bold;">Colour Index:</span>
        <table>
                 <tr>
                  <th style="background:#ddd000;">New Ticket:</th>
                  <th style="background:#FFa500;">Ticket In Progress:</th>
                  <th style="background:rgb(255,100,0)">Ticket Closed:</th>
                  <th style="background:rgb(255,20,147);">Ticket No Cetegory:</th>
                  </tr>
            <tr>
                <th>Ticket Values available to email:</th>
            </tr>
            </table>
        
        </div><br />  
        
        <?php 
     $query = <<< QUERY
SELECT COUNT(*) AS `total`, `radnew`
FROM `support` 
WHERE
  `sup_contact` = 'Bill' AND
  `radnew` IN ('new ticket','in progress','closed','no category') 
GROUP BY `radnew`
ORDER BY 
CASE `radnew`
      WHEN 'New Ticket' THEN 0
      WHEN 'In Progress' THEN 1
      WHEN 'Closed' THEN 2
      WHEN 'No Category' THEN 3
   END
QUERY;
$stmt = $conn->prepare($query);
$stmt->execute();
echo "<table>";
$result = $stmt->get_result();
       
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  echo <<< ROW
 <tr>
    <td>Bill</td>
    <td>{$row['radnew']}</td>
    <td> <input type="text" readonly name="values[{$row['radnew']}]" value="{$row['total']}" />{$row['total']}</td>
  </tr>
ROW;
  
}
echo "</table>";
           
        ?>
        
               <!-- email form -->
        
        <form id="formSend" name="formSend" method="get" action="emailedforms/status_emails.php">
              <table width="50" border="0" cellpadding="0">
                <tr>
                 
                     <td width="15"><input style="font-size:12px; font-style: italic; color: #999999" name="emailAddress" type="text" class="" id="emailAddress" placeholder="email address to send to" /><br /><br />
                         <textarea style="font-size:10px; font-style: italic; color: #999999" name="comment" rows="3" cols="100"> comments</textarea></td></tr></table>
            
            
                  <table width="100" border="0" cellpadding="0">
                <tr><td width="15" valign="centre"><label>
                    <input name="button" type="submit" class="" id="button" value="Send Ticket Status metrics to email address" />
                    </label></td></tr>
              </table>  
              </form><br />
        <!-- end email form -->
        </div>

    </body>
</html>

Open in new window


Here is my current code. I just need to send all the variable values to the "emailedforms/status_emails.php" page as a string :
...emailedforms/status_emails.php?value1= & value2= & value3= etc...........

I just can't see how to implement your code in to the page. My lack of experience
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just tried and I get Page isn't working error
sorry - will try again
Thanks so much for your patience on this. Now working
I then put this code in the receiving page?:

foreach ($_POST['values'] as $radnew => $value):
    echo $radnew;
    echo $value;
endforeach;
Yep - that's it. When you POST your form (clicking on the Go button), your receiving page will get an array with all the details from your form ($_POST['values'], $_POST['emailAddress'], $_POST['comment']). The 'values' will be an array so you loop over them with the foreach.
Perfect.
Personal question open to all. How did you gain all your expertise in PHP - by working in the field, looking at scripts and working them out with logic,, formal training, tech. documents, ........
Personally, I'm self-taught in PHP. Just started dabbling with a few simple scripts to help out with mainly web design projects. Over time (and lots and lots of reading / trial / errors / Experts Exchange! etc), it all started to make more sense. My advice would be simple - read other peoples code (good and bad), ask lot's of questions, and really, really learn how to read the technical manuals - this may sound obvious, but there's a kind of art to understanding the tech docs. The definitive source of info for all things PHP is in my opinion the PHP.net manual pages but to a beginner, they often just don't make sense.

The main thing I see over and over again is not so much that people don't understand PHP - but they struggle to understand programming in general. The principles of writing robust code in PHP are simliar to writing robust code in many other programming languages, so understanding some basic principles of Programming (data types / variables / functions / classes etc) will go a long way to helping you to understand how to write better code in PHP. My PHP programming got a lot better (in my opinion) when I started writing code in C#.

Often, the code I see is just top, down procedural code, with no abstraction or structure. It makes testing / debugging / scaling incredibly difficult - this is true of any language. Dig into the code of any decent PHP package / framework etc, and you'll see a solid structure (often Object Oriented these days). They're built in a modular, testable, logical way.

Set yourself up a local development environment (WAMPServer / Vagrant Box etc), and just play. Spend some time learning how to debug your scripts - simple stuff like error reporting / var_dump / echo, to more robust solutions such as logging and exception handling. Set up your development environment with XDebug and use a decent IDE so you can literally step through your code line by and see everything that's going on. Learn how to see exactly what your code is doing and you'll soon find it starts to make way more sense. People often see PHP as a black box - they load up a script in a web browser and try and guess what's actually going on at the server. This approach will lead to headaches - I've been there.

Most importantly - have fun with it :)
From my side - I came from a C/C++ background - moved into the web space - started with ASP and then moved to PHP (can't remember why).

As it is very C-like in its structure and library of functions the transition to PHP was fairly smooth - although transitioning from a C++ environment to web took some getting used to.

In terms of how one becomes proficient
1. Take on new challenges. From day 1 I was lazy. Most of the code I was writing was backend code to manage the content of the front end. There are only so many CRUD development iterations one can go through before it starts becomming tedious - so I wrote a library to dynamically build CRUD operations for the CMS of the sites I was building. The first iteration was a bit mundane but it worked. I then discovered the MVC pattern but was too busy to port what I had done. One day, as a teaching exercise, I knocked out a small MVC CMS project - very basic but it was one of those moments you get as a programmer when suddenly code comes out in one go that forms the basis of something bigger. I spent the next 8 years updating that CMS library.

2. I found EE and started answering questions. I was exposed to questions that challenged what I knew, opened doors to things I did not know. I read posts from members here (Ray, Dave, GaryC, Chris, Gonzo and many others) - I learned much from these interactions. I built a scaffolding system to enable me to put samples and test scripts together very quickly and I put a lot of time into researching my answers. This active approach to looking at problems helped me crystalize my thinking.

3. Dive into code - whenever I could I would get into the guts of open source products to see what coding style and tricks were used.

Ultimately it is about seeing what others do and trying to pass that on.

As Chris alluded to above - PHP is just the tool - the tool does not define the craftsman.
Thanks for the advice. My approach is similar but obviously, I have a ways to go
I find looking at scripts very very  informative, plus the php.net (makes sense the more code one looks at)

I do try to add comments and give code structure - I started out with Dreamweaver and very quickly realized that these types of IDE driven programs, when used to actually construct the code,  not only add so much extra (redundant) code, the code produced is impossible to edit when coming back to it after a time, or even if it has just been added. They are good for design work but scripts should be written in notepad form rather than let the IDE take control. Notepad, Notepad++  or Brackets very useful

I was amazed that pages of the GUI - driven code could be condensed to just a few lines
What really got me started was the functionality of websites - the design is relatively straight forward but the back end is just fascinating

I use xampp on a Virtual machine running Apache so the development environment  is very easy to access and use

Do you have a favorite IDE
That sounds very much like you're on a good, solid path to better coding.

Ditching DreamWeaver is probably the best thing you ever did - the code it generates is truly awful - some of the worst I've ever seen.

As for an IDE - I prefer Sublime Text. It's essentially a text editor, but with some add-ons it'll give you a solid IDE - code highlighting, XDebug compatible, GULP, bracket matching, snippets, templates plus a whole lot more. It's free with an occasional nag screen, but to buy it only costs $80 - worth every penny.
Julian - I can see the logic  path you followed
Especially Points 2 and 3
Getting into the code and seeing how it is put together, changing bits of code to see what happens, and answering questions is such a good way of getting to grips with this stuff. I find that EE is by far the best resource for PHP answers because people like you take their time in actually answering the questions which are being asked and then following up on issues which may crop up in running it
One BIG issue with google searches is that often the answers that are returned for a specific question are either vague, not answering the question or uses code that is very dated. I have had many disappointments this way which is why I always refer to EE for PHP answers. I find that for PHP, MySQl, Apache, CSS etc, EE is superb and most of my questions for EE are in this area
<?php require_once('TickTockDB.php'); ?>

<?php
error_reporting(E_ALL);
require("/phpmailertest/PHPMailer_5.2.4/class.phpmailer.php");
$breakecho = "<br />";
echo $_GET['invPath'];
echo $breakecho.$_GET['emailAddress'];
echo $breakecho.$_GET['invTotal'];
echo $breakecho.$_GET['comment'];
echo $breakecho.$_GET['invDetails'];
echo $breakecho.$_GET['invPaypal'];
echo $breakecho.$_GET['TodayDate'];
echo $breakecho.$_GET['TotalRecords'];
echo $breakecho.$_GET['NewTickets'];
echo $breakecho.$_GET['InProgress'];
echo $breakecho.$_GET['Closed'];
echo $breakecho.$_GET['NoCategory'];
foreach ($_GET['values'] as $radnew => $value):
    echo $radnew.$breakecho;
    echo $value;
endforeach;


//$path = '2205-Invoice-British Friends of BAR-ILAN University-No.265-1453153496.pdf';
//$path = '../ticktockInt/documents/Invoices/PaidInvoice-Perfect Travel Ltd-No.284-1482266230.pdf';
$location = "../";
$break = "<br />";
$pound = "£";
$space = "&nbsp;";
$path = $_GET['invPath'];
$url = '';
$mailaddress = $_GET['emailAddress'];
$invdetails = $_GET['invDetails'];
$invoicetotal = $_GET['invTotal'];
$inventas = 'http://www.inventas.co.uk';
$comment = $_GET['comment'];
$todaydate= $_GET['TodayDate'];
$totaltickets= $_GET['TotalRecords'];
$newtickets= $_GET['NewTickets'];
$inprogress= $_GET['InProgress'];
$closed= $_GET['Closed'];
$nocategory= $_GET['NoCategory'];
$supportwebsite= 'http://ticktockit.dyndns.biz:888/inventassites';
$name= 'test.pdf';
$encoding = 'base64';
$type = 'application/pdf';
$mail = new PHPMailer;
//$mail->IsSMTP();
//$mail->CharSet = 'UTF-8';
//$mail->Encoding = 'base64';
$mail->setFrom('info@ticktockit.net', 'TickTockIT');
$mail->addAddress($mailaddress, 'My Contact');
//$mail->addAddress('bill@inventas.co.uk', 'My Contact');
//$mail->addStringAttachment(file_get_contents($path), 'invoice.pdf');
//$mail->addAttachment($path, $name, $encoding, $type);
//$mail->addStringAttachment($path, $name, $encoding, $type);
$mail->addAttachment($path);
$mail->AddEmbeddedImage('images/favicon.png', 'InventasImage');
$mail->AddEmbeddedImage('', 'pplogo');
$mail->AddEmbeddedImage('images/icon.jpg', 'ttheader');
$mail->AddEmbeddedImage('images/favicon.png', 'ttheader');
$mail->Subject  = 'Invoice from TickTockIT';
$mail->Body = $Body;
$mail->IsHTML(true);
$mail->Body = 'Ticket Metrics and Attached PDF:
'.$break.$break.'Ticket Metrics Date (All Tickets to Date):'.$space.$todaydate.'
'.$break.'Total Tickets:'.$space.$totaltickets.'
'.$break.'New Tickets:'.$space.$newtickets.'
'.$break.'In Progress:'.$space.$inprogress.'
'.$break.'Closed:'.$space.$closed.'
'.$break.'No Category:'.$space.$nocategory.'
'.$break.'Invoice Amount:'.$space.$pound.''.$invoicetotal.'
'.$break.$break.'Message:'.$space.''.$comment.'
'.$break.$break.'Details:'.$invdetails.'
'.$break.$break.'For Inventas:'.$space.$paypal.'
'.$break.$break.'<img src="cid:ttheader" />
'.$break.'<a href='.$inventas.' style="text-decoration:none"><p style="font-size:30px; color: #808080">Click Here to go to Inventas web page<img src="cid:InventasImage" /></p></a>
'.$space.'(Guest Account Required)
'.$break.'<a href='.$supportwebsite.' style="text-decoration:none"><p style="font-size:30px; color: #808080">Click Here to go to the Support Website src="cid:InventasImage" /></p></a>';
if(!$mail->send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}
?>

Open in new window


This is turning into a labour of love. The code :

foreach ($_GET['values'] as $radnew => $value):
    echo $radnew.$breakecho;
    echo $value;
endforeach;

Is working (near the top of the receiving page) and it shows values on the receiving page but I cannot get it to show in the body section:
$mail->Body
I am using GET just for testing
OK. I can't actually see where you're trying to add it into the Body !!

It may make sense to build a string from the values before you need them in your Body:

$myString = '';

foreach ($_GET['values'] as $radnew => $value):
    $myString .= $break . $radnew  . ":" . $space . $value;
endforeach;

Open in new window

Once you've done this, you'll have all the values stored in the $myString variable, so you can just add that into your Body:

$mail->Body = 'Ticket Metrics and Attached PDF:
'.$break.$break.'Ticket Metrics Date (All Tickets to Date):'.$space.$todaydate.'
'.$break.'Total Tickets:'.$space.$totaltickets.'
'.$break.'New Tickets:'.$space.$newtickets.'
'.$myString
...

Open in new window

Perfect - I was halfway there but  I was using {} to encapsulate the data
Thanks again
One thing that scares me the most is trying to allocate points in a long string of suggestions
I always feel I am not being fair if I don't give everyone 100% but I suppose I must work in the bounds of EE
I have used the code from Julian and Chris in two different pages so I can reach the same result in different ways and so expand my learning
No worries. It's always tricky to award points when there's been a detailed converstion.