MikhailGrymkabin Posted November 6, 2013 Share Posted November 6, 2013 Hi, my code seemingly will not send the table data through email, the Table headers are sent fine, but anything after the while loop does not get sent, looking to remedy this issue.[ic]$to= 'mldecota@plymouth.edu'; <?php $to= 'mldecota@plymouth.edu'; $sub = "Hi"; $header = "Content-type: text/html"; $con = mysql_connect('localhost', 'sysop', 'Rotten210'); if (!$con){ die('could not connect' . mysql_error()) ; } $db_selected = mysql_select_db('mldecota', $con); if (!$db_selected) { die ('Borked ' . mysql_error()); } $result = mysql_query('SELECT * FROM data'); if (!$result) { die('Invalid query: ' . mysql_error()); } echo'completed succesfully'; echo "<table border='1'> <tr> <th>Date</th> <th>Time</th> <th>Machine</th> <th>Action</th> <th>User</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Time'] . "</td>"; echo "<td>" . $row['Machine'] . "</td>"; echo "<td>" . $row['Action'] . "</td>"; echo "<td>" . $row['USER'] . "</td>"; echo "</tr>"; } echo "</table>"; $msg = "<table border='1'> <tr> <th>Date</th> <th>Time</th> <th>Machine</th> <th>Action</th> <th>User</th> </tr>"; while($row1 = mysql_fetch_array($result)){ $msg.= "<tr>"; $msg.= "<td>" . $row1['Date'] . "</td>"; $msg.= "<td>" . $row1['Time'] . "</td>"; $msg.= "<td>" . $row1['Machine'] . "</td>"; $msg.= "<td>" . $row1['Action'] . "</td>"; $msg.= "<td>" . $row1['USER'] . "</td>"; $msg.= "</tr>"; } $msg .= "</table>"; mail($to,$sub,$msg,$header); mysql_close($con); ?> <?php phpinfo(); ?> Quote Link to comment Share on other sites More sharing options...
MikhailGrymkabin Posted November 6, 2013 Author Share Posted November 6, 2013 solved it myself make a new variable $result1 = mysql_query('SELECT * FROM data'); if (!$result) { die('Invalid query: ' . mysql_error()); } call it down at the while loop while($row1 = mysql_fetch_array($result1)){ Quote Link to comment Share on other sites More sharing options...
DavidAM Posted November 6, 2013 Share Posted November 6, 2013 Why run the same query twice. Just build the table in a variable, then echo and send the same variable: $table = "<table border='1'> <tr> <th>Date</th> <th>Time</th> <th>Machine</th> <th>Action</th> <th>User</th> </tr>"; while($row = mysql_fetch_array($result)) { $table . = "<tr>"; $table . = "<td>" . $row['Date'] . "</td>"; $table . = "<td>" . $row['Time'] . "</td>"; $table . = "<td>" . $row['Machine'] . "</td>"; $table . = "<td>" . $row['Action'] . "</td>"; $table . = "<td>" . $row['USER'] . "</td>"; $table . = "</tr>"; } $table . = "</table>"; echo $table; $msg = $table; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.