Jump to content

send query through email


IrOnMaSk

Recommended Posts

Hi, guys not sure if this is the right place for php-mysql help.

So, I've been search for 2 weeks now how to send a query result in an email. I know how to do a simple putting the query into a html table and send it using $message .= blablabla.

but what i'm looking for is little bit complicated. Any of you looking for a challenge, I promise this will be a challenge (I hope!!!). So I have a table function and call it every time I need to use it rather than create table and <tr><td> and put it into the message body. I don't know how to put the table function into the message body and send through email.

here's the code:

 

<?php
function viewtable($result)
{
include 'opendb.php';

if ($conn) 
{ 
     
     echo "<table border=\"0\" border-width=\"thin\" valign=\"top\" cellspacing=\"3\" cellpadding=\"3\" width=\"100%\"><tr>"; 

     //print field name 
     $colName = odbc_num_fields($result); 
     for ($j=1; $j<= $colName; $j++) 
     {  

      if (odbc_field_name($result,$j) != "App_ID")
          {
         echo "<th align=\"left\">"; 
             echo odbc_field_name ($result, $j ); 
             echo "</th>"; 
      }
     } 

     //fetch the data from the database 
     while(odbc_fetch_row($result)) 
     { 
          echo "<tr align=\"left\">"; 
          for($i=1;$i<=odbc_num_fields($result);$i++) 
          { 

         if (odbc_field_name($result,$i) == "App_ID")
         {
            $app = odbc_result($result,$i); 
         }
         else
         {
                  echo "<td align=\"left\">"; 
            if (odbc_field_name($result,$i) == "Amount Due" || odbc_field_name($result,$i) == "Net Due")
            {echo "$";}
                  echo odbc_result($result,$i); 
                  echo "</td>"; 
         }
          } 
      echo "<TD><br><form method = \"post\" action = \"app.php\">";
      echo "<input type = \"hidden\" name = \"app\" value = $app>";
      echo "<input type = \"submit\" value = \"View Application\"></form></TD>";
      echo "</TR>";
     } 
     echo "</td> </tr>"; 
     echo "</table >"; 
} 
else echo "odbc not connected";  
}
function useful_odbc_num_rows($result){
      $num_rows=0;
      while($temp = odbc_fetch_into($result, $counter))
      {
             $num_rows++;
      }
   @odbc_fetch_row($result, 0);   // reset cursor
      return $num_rows;
} 
?>

The rest is in the attachment...

Challenging you, helping me :)

 

I'm in the wrong place, have some grace and direct to the right one....

thanks in advance

 

MOD EDIT: code tags added.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/240571-send-query-through-email/
Share on other sites

  • 2 weeks later...

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.