Insert mysql query into a variable

Asked

Viewed 325 times

-1

Personal I am making a code to send email via phpmiler the problems is in how to generate an html as body of the email containing variables. Type

 Tipo arquivo html.php

 $variavel = "
 <html>...
 <body>...
 $cmd = "SELECT *FROM cotacao where c.cod = '12015172607'   ";      
  $produtos = mysql_query($cmd);
  $total = mysql_num_rows($produtos);
  while ($linha = mysql_fetch_array($produtos)) {

  echo  $id_produtos = $linha['id_produtos'];

 </body>
 </html>
 ";

And I have the code of the phpmiler that I take this $variaval

 include"html.php";// aonde esta a variavel
 $mail->isHTML(true);  // Set email format to HTML

 $mail->Subject = $assunto;
 $mail->Body    = $variavel;  aqui recupero a variavel com o html
 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

The problem is how to make a mysql SELECT inside a variaval

  • I believe that is already answered here http://answall.com/questions/5580/php-showa-variable (Because it’s a matter of basic knowledge of Mysql and PHP, there are a lot of site questions that show Mysql queries being stored in variables, I would suggest searching the site by PHP and Mysql tags)

1 answer

1


Make the query first then call or replace the variables in the template file:

html.php

$cmd = "SELECT *FROM cotacao where c.cod = '12015172607'   ";      
$produtos = mysql_query($cmd);
$total = mysql_num_rows($produtos);

 $template = "
 <html>...
 <body>...
 Produtos: <br>"; 

while ($linha = mysql_fetch_array($produtos)) {
   $template .=  $linha['id_produtos'] .'<br'>;
}

$template .= "</body></html>";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.