Jump to content

display table in mail()


hanwei

Recommended Posts

hi, to make it clearer, i repost the question again.


the structure of my table is as below when i do a select command:
--------------------------
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 script below and it only print out 1 data

Ticket Number: 4
Company: GR
Status:Assigned
Engineer Assigned: hanwei
----------------------------------



so can anyone tell me what should i add inside the script to print out all the data where ttStatus!='Closed'?

e.g
-------------------------
ttNo:1
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:2
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------
ttNo:4
ttCompany:GR
ttStatus:Assigned
ttEngrAsgn:hanwei
--------------------------

thanks


[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()");


$to = "hanwei<[email protected]>";
$subject = "test";



$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))
{


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


$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]
Link to comment
https://forums.phpfreaks.com/topic/26051-display-table-in-mail/
Share on other sites

[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()");


$to = "hanwei<[email protected]>";
$subject = "test";
$message="";



$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))
{


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


$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]

Orio.
Link to comment
https://forums.phpfreaks.com/topic/26051-display-table-in-mail/#findComment-119089
Share on other sites

............ i just need to add $message="";  ?!!!! :o

kk.. i try.. thanks alot..

and by the way, if i want to print it in this format:

--------------------------------------------------------------------------------------------------------
l      Number      l    Company        l          Status        l        EngineerAssigned      l
--------------------------------------------------------------------------------------------------------
          1                  GR                        Assigned                        hanwei
          2                  GR                        Assigned                        hanwei
          4                  GR                        Assigned                        hanwei
--------------------------------------------------------------------------------------------------------

is it possible to do it? or do i have to create a table?? thanks.. i'm a newbie in scripting..
Link to comment
https://forums.phpfreaks.com/topic/26051-display-table-in-mail/#findComment-119090
Share on other sites

[quote author=hanwei link=topic=113724.msg462374#msg462374 date=1162558223]
............ i just need to add $message="";  ?!!!! :o[/quote]
No, I also changed the part that writes into $message. From "=" to ".=".
$message .= "Ticket Number..."

[quote author=hanwei link=topic=113724.msg462374#msg462374 date=1162558223]kk.. i try.. thanks alot..

and by the way, if i want to print it in this format:

--------------------------------------------------------------------------------------------------------
l      Number       l     Company        l          Status         l         EngineerAssigned       l
--------------------------------------------------------------------------------------------------------
           1                  GR                        Assigned                         hanwei
           2                  GR                        Assigned                         hanwei
           4                  GR                        Assigned                         hanwei
--------------------------------------------------------------------------------------------------------

is it possible to do it? or do i have to create a table?? thanks.. i'm a newbie in scripting..

[/quote]
You can send HTML mail.

Orio.
Link to comment
https://forums.phpfreaks.com/topic/26051-display-table-in-mail/#findComment-119213
Share on other sites

yah i have 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()");




$to = "hanwei<[email protected]>";
$subject = "test";



$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))
{


$message = '
<html>
<head>
<title>test</title>
</head>
<body>
<table>

<TABLE BORDER=1 WIDTH="100%">
<tr BGCOLOR=#BBBBBB>
<th bgcolor="#C0C0C0" width="7%">Ticket No.</th>
<th bgcolor="#C0C0C0" width="20%">Company Name</th>
<th bgcolor="#C0C0C0" width="29%">Status</th>
<th bgcolor="#C0C0C0" width="7%">Engineer Assigned</th>

</table>
</table>
</body>
</html>
';


$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]

and it prints out the border of the table. but i doesn't know how to insert my data into the table.

can someone give me some idea?

thanks alot...
Link to comment
https://forums.phpfreaks.com/topic/26051-display-table-in-mail/#findComment-119474
Share on other sites

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.