英文:
How to take normal text from database table and change according to defined variable from other database table
问题
以下是您要翻译的代码部分:
public function customer_bill_reminder()
{
if($this->session->userdata('role') == "ADMIN" || $this->session->userdata('role') == "SUPER ADMIN")
{
$from = $this->input->post('from');
$to = $this->input->post('to');
$result = $this->MAILModel->customer_sms_reminder($from,$to);
$result2 = $this->MAILModel->auto_sms_reminder();
foreach($result2 as $row)
{
$message = @$row->sms_template;
}
foreach($result as $row)
{
$phone_number = @$row->mobile;
$year = @$row->bill_period;
$control_number = @$row->control_number;
$amount = @$row->bill_amount;
$message = "You will pay $amount in $year";
echo $message;
$this->NotificationModel->send_sms($phone_number,$message);
}
}
}
请注意,这段代码中的变量 $message
是从数据库中获取的,但您希望它的输出与硬编码的文本一样。如果输出与硬编码文本不匹配,您可能需要检查数据库中的数据以确保它们包含正确的文本。
英文:
public function customer_bill_reminder()
{
if($this->session->userdata('role') == "ADMIN" || $this->session->userdata('role') == "SUPER ADMIN")
{
$from = $this->input->post('from');
$to = $this->input->post('to');
$result = $this->MAILModel->customer_sms_reminder($from,$to);
$result2 = $this->MAILModel->auto_sms_reminder();
foreach($result2 as $row)
{
$message = @$row->sms_template;
}
foreach($result as $row)
{
$phone_number = @$row->mobile;
$year = @$row->bill_period;
$control_number = @$row->control_number;
$amount = @$row->bill_amount;
$message = "You will pay $amount in $year";
echo $message;
$this->NotificationModel->send_sms($phone_number,$message);
}
}
}
The above hard coded text from $message
will change $amount
and $year
. I have problem since the text is from the database - when I echo nothing happens, it will output exactly as it is.
I want to get the output as exactly the hard-coded text but it should be from the table.
答案1
得分: 1
$message1 = str_replace('$amount', $amount, $message);
$message2 = str_replace('$phone_number', $phone_number, $message1);
$message3 = str_replace('$control_number', $control_number, $message2);
$message4 = str_replace('$year', $year, $message3);
$this->NotificationModel->send_sms($phone_number, $message4);
英文:
$message1 = str_replace('$amount',$amount,$message);
$message2=str_replace('$phone_number',$phone_number,$message1);
$message3=str_replace('$control_number',$control_number,$message2);
$message4=str_replace('$year',$year,$message3);
$this->NotificationModel->send_sms($phone_number,$message4);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论