将数据库表中的普通文本根据另一个数据库表中定义的变量进行更改。

huangapple go评论97阅读模式
英文:

How to take normal text from database table and change according to defined variable from other database table

问题

以下是您要翻译的代码部分:

  1. public function customer_bill_reminder()
  2. {
  3. if($this->session->userdata('role') == "ADMIN" || $this->session->userdata('role') == "SUPER ADMIN")
  4. {
  5. $from = $this->input->post('from');
  6. $to = $this->input->post('to');
  7. $result = $this->MAILModel->customer_sms_reminder($from,$to);
  8. $result2 = $this->MAILModel->auto_sms_reminder();
  9. foreach($result2 as $row)
  10. {
  11. $message = @$row->sms_template;
  12. }
  13. foreach($result as $row)
  14. {
  15. $phone_number = @$row->mobile;
  16. $year = @$row->bill_period;
  17. $control_number = @$row->control_number;
  18. $amount = @$row->bill_amount;
  19. $message = "You will pay $amount in $year";
  20. echo $message;
  21. $this->NotificationModel->send_sms($phone_number,$message);
  22. }
  23. }
  24. }

请注意,这段代码中的变量 $message 是从数据库中获取的,但您希望它的输出与硬编码的文本一样。如果输出与硬编码文本不匹配,您可能需要检查数据库中的数据以确保它们包含正确的文本。

英文:
  1. public function customer_bill_reminder()
  2. {
  3. if($this->session->userdata('role') == "ADMIN" || $this->session->userdata('role') == "SUPER ADMIN")
  4. {
  5. $from = $this->input->post('from');
  6. $to = $this->input->post('to');
  7. $result = $this->MAILModel->customer_sms_reminder($from,$to);
  8. $result2 = $this->MAILModel->auto_sms_reminder();
  9. foreach($result2 as $row)
  10. {
  11. $message = @$row->sms_template;
  12. }
  13. foreach($result as $row)
  14. {
  15. $phone_number = @$row->mobile;
  16. $year = @$row->bill_period;
  17. $control_number = @$row->control_number;
  18. $amount = @$row->bill_amount;
  19. $message = "You will pay $amount in $year";
  20. echo $message;
  21. $this->NotificationModel->send_sms($phone_number,$message);
  22. }
  23. }
  24. }

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);

英文:
  1. $message1 = str_replace('$amount',$amount,$message);
  2. $message2=str_replace('$phone_number',$phone_number,$message1);
  3. $message3=str_replace('$control_number',$control_number,$message2);
  4. $message4=str_replace('$year',$year,$message3);
  5. $this->NotificationModel->send_sms($phone_number,$message4);

huangapple
  • 本文由 发表于 2023年6月15日 16:38:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定