循环电子邮件正文中的内容


Looping content in email body

我想在电子邮件正文中循环一些内容,但我不知道如何做到。:D请帮忙(

<?php
    $db_username = 'ads';
    $db_password = 'sad';
    $db_name = 'asdasd';
    $db_host = 'asd.com';
    $mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
?>
$results = $mysqli->query("SELECT * FROM products ORDER BY id ASC");
foreach( mysql_fetch_array($results) as $item ) {
    $message = '<html>
                        <head>
                        <title>From our company</title>
                        </head>
                        <body>
                            <div id="newsletter-product" style="border:1px solid gray; overflow:hidden; width:500px; margin:0 auto; text-align:center;">  
                                //I WANT TO LOOP THIS DIV//
                                <div id="newsletter-organic" style="float:left; width:50%;">
                                  <h1> Organik </h1>
                                    <p><img src="http:mywebsite/images/'.$item['product_img_name'].'" width:150px; height:200px;"></p>
                                      <a href="http://mywebsite.com/get-referal.php?referal_identity='.$referal_identity.'&referal_address='.$referal_address.'&productName='.$item['product_name'].'">
                                        <p>Beras Putih</p></a><br/>
                                </div>                    
                            </div>
                        </body>
                        </html>';
}

我要循环的是产品。

谢谢你帮我做这件事。:)

试试这个

<?php
        $db_username = 'ads';
        $db_password = 'sad';
        $db_name = 'asdasd';
        $db_host = 'asd.com';
        $con =  mysqli_connect($db_host, $db_username, $db_password,$db_name);

        $results = mysqli_query($con,"SELECT * FROM products ORDER BY id ASC");
         $message='';
         while( $item=mysqli_fetch_array($con,$results)  ) {
                    $message. = '<html>
                                <head>
                                <title>From our company</title>
                                </head>
                                <body>
                                    <div id="newsletter-product" style="border:1px solid gray; overflow:hidden; width:500px; margin:0 auto; text-align:center;">  
                                        //I WANT TO LOOP THIS DIV//
                                        <div id="newsletter-organic" style="float:left; width:50%;">
                                          <h1> Organik </h1>
                                            <p><img src="http:mywebsite/images/'.$item['product_img_name'].'" width:150px; height:200px;"></p>
                                              <a href="http://mywebsite.com/get-referal.php?referal_identity='.$referal_identity.'&referal_address='.$referal_address.'&productName='.$item['product_name'].'">
                                                <p>Beras Putih</p></a><br/>
                                        </div>                    
                                    </div>
                                </body>
                                </html>';
                  }
You can try this, in the code there are only "newsletter-organic" d
<?php
        $db_username = 'ads';
        $db_password = 'sad';
        $db_name = 'asdasd';
        $db_host = 'asd.com';
        $mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
        ?>
        $results = $mysqli->query("SELECT * FROM products ORDER BY id ASC");
        $message = '<html>
                        <head>
                        <title>From our company</title>
                        </head>
                        <body>
                            <div id="newsletter-product" style="border:1px solid gray; overflow:hidden; width:500px; margin:0 auto; text-align:center;">';
    foreach( mysql_fetch_array($results) as $item ) {
                                //I WANT TO LOOP THIS DIV//
                                $message .= '<div id="newsletter-organic" style="float:left; width:50%;">
                                  <h1> Organik </h1>
                                    <p><img src="http:mywebsite/images/'.$item['product_img_name'].'" width:150px; height:200px;"></p>
                                      <a href="http://mywebsite.com/get-referal.php?referal_identity='.$referal_identity.'&referal_address='.$referal_address.'&productName='.$item['product_name'].'">
                                        <p>Beras Putih</p></a><br/>
                                </div>';                    
          }
          $message .= '</div>
                    </body>
                 </html>';
$results = $mysqli->query("SELECT * FROM products ORDER BY id ASC");
            foreach( mysql_fetch_array($results) as $item ) {
            $message = '<html>
                        <head>
                        <title>From our company</title>
                        </head>
                        <body>
                            <div id="newsletter-product" style="border:1px solid gray; overflow:hidden; width:500px; margin:0 auto; text-align:center;">';
                            for ($i = 1; $i <= 10; $i++) {
                                //I WANT TO LOOP THIS DIV// this div will loop 10 times...
                                $message .= '<div id="newsletter-organic" style="float:left; width:50%;">
                                  <h1> Organik </h1>
                                    <p><img src="http:mywebsite/images/'.$item['product_img_name'].'" width:150px; height:200px;"></p>
                                      <a href="http://mywebsite.com/get-referal.php?referal_identity='.$referal_identity.'&referal_address='.$referal_address.'&productName='.$item['product_name'].'">
                                        <p>Beras Putih</p></a><br/>
                                </div>';  
                              }             
                    $message .= '         </div>
                        </body>
                        </html>';
          }

是的,正如Ram Sharma所写,您使用的是对象$mysqli,然后是mysql函数mysql_fetch_array。。。

您有多个错误

不要混合mysqlimysql

您使用的是mysql_fetch_array($results) as $item而不是mysqli

也将$message =更改为$message.=