Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.