将while函数的结果放入字符串中的最佳做法是什么。
例如:
while($row2 = mysql_fetch_assoc($select2)){
echo "id:".$id."<br />";
echo "Job Title: ".$title."<br />";
echo "Email: ".$email."<br />";
}
$message = $row2;
这是我尝试过的,但找不到合适的方法。非常感谢
答案 0 :(得分:2)
连接它:
$message = '';
while($row2 = mysql_fetch_assoc($select2)){
$message .= "id:".$id."<br />";
$message .= "Job Title: ".$title."<br />";
$message .= "Email: ".$email."<br />";
}
echo $message;
答案 1 :(得分:2)
我更喜欢使用数组。
$message = "";
while($row2 = mysql_fetch_assoc($select2)){
$message[] = "id:".$row2['id'];
$message[] = "Job Title: ".$row2['title'];
$message[] = "Email: ".$row2['email'];
}
echo implode('<br />', $message);
答案 2 :(得分:0)
使用字符串concat运算符:
$message = "";
while($row2 = mysql_fetch_assoc($select2)){
$message .= "id:".$id."<br />";
$message .= "Job Title: ".$title."<br />";
$message .= "Email: ".$email."<br />";
}
echo $message;