gpt4 book ai didi

mysql - php foreach 每个结果在一个变量中

转载 作者:行者123 更新时间:2023-11-29 05:25:10 25 4
gpt4 key购买 nike

我试图将查询的每个结果放入一个变量中,以便我可以将其包含在我的 wp_mail 消息中。

这就是我正在使用的。

$result = $wpdb->get_results("SELECT * 
FROM $tableName
WHERE userId = $user_ID
AND status LIKE '1'"
);
foreach( $result as $key => $value)
{
$string .= $value.',';
}

echo $string;
$email = $_POST['parentsEmail'];
$child = $_POST['childsName'];
wp_mail( $email, "".$child." has finished", "".$child." has completed the following ".$string." ");

我一直在搜索,发现另一个线程询问类似的东西,这是建议的。

$string .= $value.',';

但是当我尝试做同样的事情时,我得到了

可捕获的 fatal error :stdClass 类的对象无法转换为字符串

最佳答案

你可以用这个代替mysql

SELECT 
CONCAT(col1,col2,col3) `value`
FROM $tableName
WHERE userId = $user_ID AND status LIKE '1'

你可以用这个代替mysql ok

关于mysql - php foreach 每个结果在一个变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com