使用foreach循环通过url发送查询字符串值
问题描述:
我正在为应用程序使用codeigniter。首先,我创建了包含Message TextArea Box,DropDownlist,其值来自数据库并提交按钮的视图。我有两个colums一个用于手机号码和另一个服务提供商的数据库。我有预定义的URL与查询字符串值(http://www.something.com?mobno=numbervar & msg = messagevar)使用foreach循环通过url发送查询字符串值
在模型类,我有一个名为getProvider1的函数,以获得返回特定提供者的移动号码的数组。我应该使用上面的URL来查询字符串,传递用户输入的手机号码和消息。在这里,我使用foreach循环通过查询字符串将消息传递给不同的手机号码。
问题是,我无法知道如何将消息传递到多个手机号码,而无需访问那些something.com页面,并显示结果哪个查询字符串值被传递,哪些失败......在这里,我不能' t使用foreach在该URL中传递不同的查询字符串值。它只访问一个页面或重定向一次....是否有任何功能像重定向()....或任何其他选项。请想一些建议...将不胜感激....以下是控制器的功能,首先发送消息
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
}
}
答
,我不是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;
}
}