【问题标题】:Sending query string value through url using foreach loop使用 foreach 循环通过 url 发送查询字符串值
【发布时间】:2012-01-09 01:06:26
【问题描述】:

我正在为应用程序使用 codeigniter。首先,我创建了由 Message TextArea Box 、来自数据库的 DropDownlist 和提交按钮组成的视图。我有两列的数据库,一个用于手机号码,另一个用于服务提供商。我已经预定义了带有查询字符串值的 url (http://www.something.com?mobno=numbervar&msg=messagevar)

在模型类中,我有一个名为 getProvider1 的函数,用于返回特定提供商的手机号码数组。我应该使用上面的 url 和查询字符串来传递用户输入的手机号码和消息。这里我使用了foreach循环通过查询字符串将消息传递给不同的手机号码。

问题是我不知道如何在不访问 something.com 页面的情况下将消息传递到多个手机号码并显示结果,哪个查询字符串值被传递,哪些失败......在这里,我不能使用 foreach 在该 url 中传递不同的查询字符串值。它只访问一个页面或重定向一次......是否有类似redirect()......或任何其他选项的功能。请提出一些建议...将不胜感激...以下是控制器发送消息的功能

function message()
{               $message = $this->input->post('message');
        $provider = $this->input->post('provider');

        if($provider == 'provider1')
        {
            $number = $this->message_model->getProvider1();
            $mobile = array();
            foreach($number as $no)
            {
                $mobile = $no;

            redirect('http://something.com?mobno='.$mobile.'&msg='.$message);
            }


        }

               else if
                {
                     // same process for service provider2
                }
               else
                {
                  //other service provider
                }
     }

【问题讨论】:

    标签: php codeigniter url


    【解决方案1】:

    首先,我不能 100% 确定您到底想做什么,但重定向显然只会工作一次(因为在您重定向后,您不再在您的页面上)。

    根据我对您的代码的理解,您可以做的是查看cURL。它让您有机会加载多个页面并“在幕后”查看它们的结果,并向用户展示您想要的任何内容。

    其他一些注释。

    /* Instead of doing the same thing for all provides with IFs, rewrite you message model to take the provider name as a input variable insdead. */
    $number = $this->message_model->getProvider($provider);
    /* $mobile = array(); // you never use this array, no need for it */
    foreach($number as $mobile)
    {
      /* $mobile = $no; //completly useless, just name it in the foreach */
    
      /* --- do a cURL request here --- */
      $curl = curl_init(); 
      curl_setopt($curl, CURLOPT_URL, 'http://something.com?mobno='.$mobile.'&msg='.$message);
      $curl_info = curl_getinfo($curl);
      curl_close($curl);
      if ($curl_info['http_code'] != 200) /* Handle error if any */
      {
        $errors[] = 'ERROR WITH REQUEST: http://something.com?mobno='.$mobile.'&msg='.$message;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 2011-01-17
      • 1970-01-01
      • 2014-06-29
      相关资源
      最近更新 更多