Reputation: 31
I have a web-based sign out sheet that displays a list of currently signed out assets (it does this by pulling the variables from an SQL table) I wan to take the same output and send it in an email but every time I try I either get resource id#4 or a blank output. For reasons of confidentiality I can't put up the source code for the mail aspect as its for a client. The below works fine at displaying on the main site. The environment is using WAMP any info would be appropriated.
mysql_connect("127.0.0.1", "helpdesk", "Password" )or die("cannot connect");
mysql_select_db("loaner")or die("cannot select DB");
$table=mysql_query("SELECT * FROM signout");
echo "
<div id='status'> <table cellspacing='0' cellpadding='0' border=''>
<tr>
<th>Equipment Currently Out</th>
<th>By Who</th>
<th>Return Date</th>
</tr>";
while ($row = mysql_fetch_array($table))
{
echo "<tr>";
echo "<td>" . $row['Equip'] . "</td>";
echo "<td>" . $row['User'] . "</td>";
echo "<td>" . $row['Return Date'] . "</td>";
}
echo "</tr>";
echo "</table></div>";
echo "</table></div>";
Upvotes: 0
Views: 1016
Reputation: 3658
Note that the line breaks used with $table aren't necessary, I simply left them there to make it easier for you to see what's going on.
mysql_connect('127.0.0.1', 'helpdesk', 'Password' ) or die('cannot connect');
mysql_select_db('loaner')or die('cannot select DB');
$results = mysql_query('SELECT * FROM signout');
/**
* Store the HTML in a variable
*/
$table = "<div id='status'>
<table cellspacing='0' cellpadding='0' border=''>
<tr>
<th>Equipment Currently Out</th>
<th>By Who</th>
<th>Return Date</th>
</tr>";
while ( $row = mysql_fetch_array($results) ) {
$table .= "<tr>";
$table .= "<td>" . $row['Equip'] . "</td>";
$table .= "<td>" . $row['User'] . "</td>";
$table .= "<td>" . $row['Return Date'] . "</td>";
}
$table .= "
</tr>
</table>
</div>";
/**
* Mail the HTML
*/
$body = 'Blah blah blah '.$table.' blah blah blah';
mail($to, $from, $subject, $body);
Upvotes: 1