Greetings,
I am trying to create a script that will email (plain text) the results of a few MYSQL queries.
How can I get the table to align properly? I have considered storing the MYSQL results into an array and the using strlen() to find the longest in each field and position it properly with \t. Is this the best way?
Id apreciate any help and/or suggestions.
Thanks,
Leonard.
/
When I was a kid I was never interested in history, now that I am older is that history history?
/
<? php;
if ($redirect!="go")
{
die;
}
include "dbconnect.inc";
include "functions.inc";
$i=0;
$from = "foo@bar.com";
$cc = "foo@bar.com";
$to = "foo@bar.com";
$sub = "Monthly Report for $mon $yr";
$msg[$i]="Revenue for $mon $yr\n";
$i++;
$msg[$i]="Date\t\t\t Customer \t\t Amount \n";
$i++;
//Queries to get income info.
$result[1]= mysql_query("select * from ledger_income
where left(date, 6)=$disp_month order by auto asc");
$result[2]= mysql_query("select sum(amount) as sum from ledger_income
where left(date, 6)=$disp_month order by auto asc");
$result[3]= mysql_query("select * from ledger_expense
where left(date, 6)=$disp_month order by auto asc");
$result[4]= mysql_query("select sum(amount) as sum from
ledger_expense where left(date, 6)=$disp_month order by auto asc");
//Get data from tables
if ($result[1])
{
while ($row = mysql_fetch_array($result[1]))
{
$cust = $row["customer"];
$cust = get_acct_names($cust, customer);
$msg[$i]=$row["date"]."\t\t".$cust."\t\t$".number_format($row["amount"],
2)."\n";
$i++;
}
mysql_free_result($result[1]);
}
$z++;
if ($result[2])
{
while ($row = mysql_fetch_array($result[2]))
{
$rev= $row["sum"];
$msg[$i]= "Total\t\t\t\t$".number_format($rev, 2);
$i++;
}
mysql_free_result($result[2]);
}
$msg[$i]="\n\n\n";
$i++;
$msg[$i]="Expense for $month\n";
$i++;
$msg[$i]="Date\t\t\t Customer \t\t Amount \n";
$i++;
if ($result[3])
{
while ($row = mysql_fetch_array($result[3]))
{
$ven = $row["vendor"];
$vendor = get_acct_names($ven, vendor);
$msg[$i]=$row["date"]."\t\t".$vendor."\t\t$".number_format($row["amount"],
2)."\n";
$i++;
}
mysql_free_result($result[3]);
}
if ($result[4])
{
while ($row = mysql_fetch_array($result[4]))
{
$exp=$row["sum"];
$msg[$i]= "Total\t\t\t\t$".number_format($exp, 2);
$i++;
}
mysql_free_result($result[4]);
}
$net = $rev-$exp;
if ($net > 0)
{
$payout = $net/2;
$payout = "$".number_format($payout, 2);
}
else
{
$payout = "No Payout";
}
$msg[$i]="\n\n\n";
$i++;
$msg[$i]="Revenue\tExpense\tNet\n";
$i++;
$msg[$i]="$".number_format($rev, 2)."\t$".number_format($exp,
2)."\t$".number_format($net, 2)."\n";
$i++;
$msg[$i]="\n\n\n";
$i++;
$msg[$i]="\tPayout\n";
$i++;
$msg[$i]="Julie\t$payout\n";
$i++;
$msg[$i]="Judie\t$payout\n";
for ($j=0; $j <= $i; $j++)
{
$message=$message.$msg[$j];
}
//Send mail and print confirmation to screen
mail($to, $sub, $message, "From: $from\n");
print "Message Sent";
?>