0

Just looking for better solution.I'm retrieving all the records from mysql. Then I will send this data by email. Its working fine. Is there any better solution? thanks

$query = "SELECT * FROM order_details WHERE order_id = '".$data['order_id']."'";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    $message_admin .= "<table  style='text-align:center;' border='1' cellspacing='0' cellpadding='7'> 
        <tr>
            <td>Source</td>
            <td>".$data['source']."</td>
        </tr>
        <tr>
            <td>Email</td>
            <td>".$data['email']."</td>
        </tr>
        <tr>
            <td>Message</td>
            <td>".$data['message']."</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>";
    }
no_freedom
  • 1,963
  • 10
  • 30
  • 48

2 Answers2

0

You would benefit from: http://us.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Instead of the complicated string manipulation you are doing now.

You are setting $row, but using $data?

Ariel
  • 25,995
  • 5
  • 59
  • 69
  • When I print this variable. `echo $message_admin`. It displayed the data. I'm passing this variable to mail. And I'm getting empty message. What wrong with this code? Thanks for pointing me error `$row`. – no_freedom Sep 14 '11 at 18:09
  • Mail function `$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to_client, $subject_client, $message_admin, $headers);` – no_freedom Sep 14 '11 at 18:10
  • I'm not sure what's wrong. Try sending a simple test message with php first, then put in the code you wrote. – Ariel Sep 15 '11 at 01:20
  • Simple test message delivered successfully. – no_freedom Sep 15 '11 at 06:24
  • OK, now keep making changes one at a time till you find the change that causes a blank message. – Ariel Sep 15 '11 at 06:58
0

I would take a look at the following to improve your code.

mysql-real-escape-string

SELECT * vs SELECT column

Community
  • 1
  • 1
Bruce
  • 1,542
  • 13
  • 17