0 レビュー
4 回答
php-メール本文のコンテンツをループする
メール本文の一部のコンテンツをループしたいのですが、その方法がわかりません。 :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>';
}
ループするのは製品です。
これを手伝ってくれてありがとう。 :)
わからない
0
レビュー
答え :
解決策:
これを試してください
<?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>';
}
わからない
0
レビュー
答え :
解決策:
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>';
わからない
0
レビュー
答え :
解決策:
$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>';
}
はい。RamSharmaが書いたように、オブジェクト $mysqli
を使用してから、 mysql
関数{-codeを使用しています。 -3} _fetch_array
...
わからない
0
レビュー
答え :
解決策:
複数のエラーがあります
mysqli
とmysql
mysqli
mysql_fetch_array($ results)を$ item
として使用しています
また、 $message =
を$message.=
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。