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

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

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

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:

确定