0

This is my email.php page coding. My php email function code working perfectly. I'm faced a small problem here. I didn't get the database records inside the while($t_row = mysql_fetch_array($tariff_query)){}. But, it send the remaining records from database correctly. How to send the database records of inside the while($t_row = mysql_fetch_array($tariff_query)){}?

include("config.php");
    if(isset($_GET["id"]))
    {
        $id = mysql_real_escape_string($_GET["id"]);
        $query = mysql_query("SELECT * FROM ebvouchers WHERE VoucherID = $id");
        $row = mysql_fetch_object($query);
        echo mysql_error();
        $tariff_query = mysql_query("SELECT * FROM ebvouchertariffs WHERE VoucherID_Fk = $id");

    $strMessage = "<table width=1200 align=center cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>
    <tr>
      <td width=1026 height=8 colspan=2>&nbsp;</td>
    </tr>
      <tr>
        <td colspan=8>
        &nbsp;
        <table class=glow width=1070 border=0 align=center cellpadding=0 cellspacing=0>
          <tr>
            <td height=40 colspan=4 style=border-radius: 5px 5px 0px 0px; class=headdetail>GUEST DETAILS </td>
            </tr>
          <tr>
            <td width=263 height=10 class=detailsfont>&nbsp;</td>
            <td width=228>&nbsp;</td>
            <td width=239 class=detailsfont>&nbsp;</td>
            <td width=340>&nbsp;</td>
          </tr>
          <tr>
            <td height=40 class=detailsfont>Voucher ID :</td>
            <td width=228 class=fetchfont>$row->VoucherID</td>
            <td width=239 class=detailsfont>Voucher Reference Number :</td>
            <td width=340 class=fetchfont>$row->VoucherReference</td>
          </tr>
         //some codes
         //some codes
         //some codes
         //some codes
         //some codes
         //some codes
         //some codes
          <tr>
            <td colspan=4>
            &nbsp;
            <table class=myborder width=1050 border=0 align=center cellpadding=10 cellspacing=0>
              <tr>
                <td width=70 height=40 class=tarifffont>Serial No</td>
                <td width=130 class=tarifffont>Date</td>
                <td width=250 class=tarifffont>Particulars</td>
                <td width=100 class=tarifffont>No of Nights</td>
                <td width=100 class=tarifffont>Rate</td>
                <td width=100 class=tarifffont>Price</td>
                <td width=100 class=tarifffont>Tax %</td>
              </tr>";
              while($t_row = mysql_fetch_array($tariff_query))
                {
                    "<tr>
                    <td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
                    <td class=insidetariff>". $t_row['TariffDate'] ."</td>
                    <td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
                    <td class=insidetariff>". $t_row['NoOfNights'] ."</td>
                    <td class=insidetariff>". $t_row['TariffRate'] ."</td>
                    <td class=insidetariff>". $t_row['TariffPrice'] ."</td>
                    <td class=insidetariff>". $t_row['TariffTax'] ."</td>
                    </tr>";
                }
              "<tr>
                <td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
                <td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
                <td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
                <td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
                </tr>
              <tr>
                <td height=20 colspan=7 class=detailsfont>&nbsp;</td>
                </tr>
              <tr>
                <td height=40 colspan=5 class=detailsfont>Final Amount : </td>
                <td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
                </tr>
            </table></td>
            </tr>
            <td colspan=4>&nbsp;</td>
        </table>
        </td>
      </tr>";
    }

4 Answers 4

1

You must append the data to the string. So the code will be like this:

while ($t_row = mysql_fetch_array($tariff_query)) {
    $strMessage .= "<tr>
    <td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
    <td class=insidetariff>". $t_row['TariffDate'] ."</td>
    <td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
    <td class=insidetariff>". $t_row['NoOfNights'] ."</td>
    <td class=insidetariff>". $t_row['TariffRate'] ."</td>
    <td class=insidetariff>". $t_row['TariffPrice'] ."</td>
    <td class=insidetariff>". $t_row['TariffTax'] ."</td>
    </tr>";
}
$strMessage .= "<tr>
<td height=40 colspan=2 class=detailsfont>Total Price (Overall Price)....

Also, use of mysql_* functions is deprecated and will be removed in the future. You should use mysqli_* functions now.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks..its working... i'm a beginner.. how to use mysqli, pdo function instead of mysql. provide me some useful links..
@Indian, glad it worked. Here is some information about mysqli. HERE is another stackoverflow question, and the answer describes very simple the basic needs.
1

You going wrong way.First assign while loop data to variable then add to mail message like this:

$tbl = '';

 while($t_row = mysql_fetch_array($tariff_query))
                {
                  $tbl .= "<tr>
                    <td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
                    <td class=insidetariff>". $t_row['TariffDate'] ."</td>
                    <td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
                    <td class=insidetariff>". $t_row['NoOfNights'] ."</td>
                    <td class=insidetariff>". $t_row['TariffRate'] ."</td>
                    <td class=insidetariff>". $t_row['TariffPrice'] ."</td>
                    <td class=insidetariff>". $t_row['TariffTax'] ."</td>
                    </tr>";
                }

while now on you message add this variable like this :

  $strMessage = "<table>.....".$tbl."....";

Comments

0

You are not concatenating the string for variable $strMessage.

In while loop you should concate string with your variable and at last echo it.

Comments

0

Store data calculated inside the while loop as :

 while($t_row = mysql_fetch_array($tariff_query))
                {
                  $strMessage  .= "<tr>
                    <td class=insidetariff>". $t_row['TariffSlNo'] ."</td>
                    <td class=insidetariff>". $t_row['TariffDate'] ."</td>
                    <td class=fetchfont>". $t_row['TariffParticulars'] ."</td>
                    <td class=insidetariff>". $t_row['NoOfNights'] ."</td>
                    <td class=insidetariff>". $t_row['TariffRate'] ."</td>
                    <td class=insidetariff>". $t_row['TariffPrice'] ."</td>
                    <td class=insidetariff>". $t_row['TariffTax'] ."</td>
                    </tr>";
                }

And also assign string after while loop to $strMessage :

 $strMessage .= "<tr>
                <td height=40 colspan=2 class=detailsfont>Total Price (Overall Price) : </td>
                <td height=20 colspan=2 class=tarifffont>$tt_row->TariffAddTotal</td>
                <td height=20 class=insidetariff>Net Total (Overall Tax) : </td>
                <td height=20 colspan=2 class=tarifffont>$tt_row->TariffNetTotal</td>
                </tr>
              <tr>
                <td height=20 colspan=7 class=detailsfont>&nbsp;</td>
                </tr>
              <tr>
                <td height=40 colspan=5 class=detailsfont>Final Amount : </td>
                <td height=40 colspan=2 class=tarifffont>$tt_row->TariffFinalTotal</td>
                </tr>
            </table></td>
            </tr>
            <td colspan=4>&nbsp;</td>
        </table>
        </td>
      </tr>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.