Jump to content

email - get table from database


hanwei

Recommended Posts

hi guys,

how can i get the whole table from my data and display it to my mail??

the structure of the table is as below when i do a select statement:

--------------------------
ttNo:1
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:2
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:3
ttCompany:GR
ttStatus:Closed
ttEngrAsgn:hanwei
--------------------------
ttNo:4
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------



i have tried the following script:
[code]<?php

$link = mysql_connect("127.0.0.1", "mysql") or die("Could not connect: " .
mysql_error());
mysql_select_db("ttmodule", $link) or die("Unable to select database: .
mysql_error()");

$selectSqlOne= "SELECT * FROM indexpri ORDER BY indexPriNo ASC ";
$resultOne = mysql_query($selectSqlOne, $link);
if(!$resultOne) die("Invalid Query: " .mysql_error() ."<br>"
.$selectSqlOne);

while($row = mysql_fetch_array($resultOne))
{
$secondaryTbl = $row["indexSecTbl"];
$selectSqlTwo= "SELECT * FROM $secondaryTbl ORDER BY indexSecNo ASC ";
$resultTwo = mysql_query($selectSqlTwo, $link);
if(!$resultTwo) die("Invalid Query: " .mysql_error() ."<br>" .$selectSqlTwo);

while($row = mysql_fetch_array($resultTwo))
{
$mainTbl = $row["mainTbl"];
$selectSqlThree="SELECT ttNo, ttCompany, ttStatus, ttEngrAsgn FROM $mainTbl where ttStatus='Closed' ORDER BY ttNo ASC";
$resultThree = mysql_query($selectSqlThree, $link);
if(!$resultThree) die("Invalid Query: " .mysql_error() ."<br>"  .$selectSqlThree);

while($row=mysql_fetch_array($resultThree))
{
$to = "hanwei<[email protected]>";
$subject = "test";

$message = "";


$headers = "From: [email protected]\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";

mail($to, $subject, $message, $headers);

}
}
}
?>
[/code]

the script works fine when i input the message as : $message=$row["ttNo"]; it will only display the ttNo.
but i want to display the whole table where ttStatus!='Closed'.

so how do i continue from here? or my script is totally wrong?
do i have to create a table border for it? i just want to display a simple table containing the variable. This table will allow the administrator to find out which company's not in Closed status.

thanks
Link to comment
https://forums.phpfreaks.com/topic/25921-email-get-table-from-database/
Share on other sites

hi,

i have tried:
$message = "Ticket Number:"."\n".$no."<br></br>"."Company:"."\n".$comp."<br></br>"."Status:"."\n".$stat."<br></br>"."Engineer Assigned:"."\n".$engr."<br></br>"."\n--------------------------";

and it will only print out the highest ticket number:  Ticket Number: 4
                                                                      Company: GR
                                                                      Status:Assigned
                                                                      Engineer Assigned: hanwei

so what can i do to make my message display all the data??
example:
-------------------------
ttNo:1
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:2
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:4
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------


and if i want to have a print out like :

------------------------------------------------------------------------------------
l      Number       l     Company        l          Status         l         EngineerAssigned       l
------------------------------------------------------------------------------------
           1                  GR                        Assigned                         hanwei
           2                  GR                        Assigned                         hanwei
           4                  GR                        Assigned                         hanwei
-------------------------------------------------------------------------------------
do i have to change my script?

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.