Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cURL,PHP-循环中的循环_Php_Loops_Curl - Fatal编程技术网

cURL,PHP-循环中的循环

cURL,PHP-循环中的循环,php,loops,curl,Php,Loops,Curl,我想要这样的东西: $i = 1; $y = 1; while($i <= 10 and $y <= 5) { if($i==10) { echo 'I = '.$i.', Y = '.$y.'<br>'; $i = 1; $y = $y+1; } else { echo 'I = '.$i.', Y = '.$y.'<br>'; $i = $i + 1; } } 等,等,与卷曲一起使用。但它不起作用。我做错了什么 $i = 1; $y = 1; whi

我想要这样的东西:

$i = 1;
$y = 1;

while($i <= 10 and $y <= 5)
{
if($i==10)
{
echo 'I = '.$i.', Y = '.$y.'<br>';
$i = 1;
$y = $y+1;
}
else
{
echo 'I = '.$i.', Y = '.$y.'<br>';
$i = $i + 1;
}
}
等,等,与卷曲一起使用。但它不起作用。我做错了什么

$i = 1;
$y = 1;

while($y <= 9)
{
while($i==499)
{
if($connection = db_connect()) 
{
$post = array('something' => 'abc', 'value_of_y' => ''.$y.'', 'value_of_i' => ''.$i.'');
$str = curl_grab_page('http://localhost/send.php?true=1','','off',$post);

$str2 = mysql_real_escape_string($str);
$sql = "INSERT INTO abc (txt) VALUES ('$str2')";

$i = 1;
$y = $y+1;
}
else
{
echo 'Database connection error!';
}
}
while($i != 499)
{
if($connection = db_connect()) 
{
$post = array('something' => 'abc', 'value_of_y' => ''.$y.'', 'value_of_i' => ''.$i.'');
$str = curl_grab_page('http://localhost/send.php?true=1','','off',$post);

$str2 = mysql_real_escape_string($str);
$sql = "INSERT INTO abc (txt) VALUES ('$str2')";

$i = $i + 1;
}
else
{
echo 'Database connection error!';
}
}
}
$i=1;
$y=1;
而($y'abc'、'value'u of'u y'=>''.$y.'、'value'u of'u of'u i'=>''.$i.');
$str=curl\u grab\u页面('http://localhost/send.php?true=1","关","邮资",;
$str2=mysql\u real\u escape\u字符串($str);
$sql=“插入abc(txt)值(“$str2”)”;
$i=1;
$y=$y+1;
}
其他的
{
echo“数据库连接错误!”;
}
}
而($i!=499)
{
如果($connection=db_connect())
{
$post=array('something'=>'abc'、'value\u of theu y'=>'.$y.'、'value\u of theu i'=>'.$i.');
$str=curl\u grab\u页面('http://localhost/send.php?true=1","关","邮资",;
$str2=mysql\u real\u escape\u字符串($str);
$sql=“插入abc(txt)值(“$str2”)”;
$i=$i+1;
}
其他的
{
echo“数据库连接错误!”;
}
}
}
但是页面一直在加载,什么也没发生。我必须使用“if($connection=db_connect()){”,但我认为这是我代码中经常出现的问题。请看一下,好吗?谢谢。

也许这是一个开始

$sql = "INSERT INTO abc (txt) VALUES ('".$str2."')";

我的解决办法如下:

$y = $x = 1;

if (!$connection = db_connect()) {
   echo "connection failed!";
} else {
   while ($y <= 9) {
     $x = 1;
     while ($x <= 499) {
       // do your things with $x and $y, don't forget mysql_query() !

       $x++;   
     }
     y++;
   }
 }
$y=$x=1;
如果(!$connection=db\u connect()){
echo“连接失败!”;
}否则{

虽然($y我不这么认为,因为它可以在没有while循环的情况下工作,但我会尝试使用tooThis语法,但这不是必需的。OP中的插入代码可以正常工作,因为字符串是双引号。是的,这没有改变任何内容,仍然没有向数据库中添加任何内容。为什么要连接500次?我会先连接,然后启动t另外,两个cURL帖子是相同的:保持干燥;不要重复你自己。如果你的数据库连接失败,你的循环将永远消失,因为你永远不会退出。对了,忘了mysql query.Thx
$y = $x = 1;

if (!$connection = db_connect()) {
   echo "connection failed!";
} else {
   while ($y <= 9) {
     $x = 1;
     while ($x <= 499) {
       // do your things with $x and $y, don't forget mysql_query() !

       $x++;   
     }
     y++;
   }
 }