0

我想要这样的东西:

$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
I = 2, Y = 1
....
I = 1, Y = 2
I = 2, Y = 2
....
I = 1, Y = 3
I = 2, Y = 3

等,等等,与 cURL 一起使用。但它不起作用。我究竟做错了什么?

$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!';
}
}
}

但是页面一直在加载,没有任何反应。我必须使用“if($connection = db_connect()){”,但我认为这就是我的代码一直在搞砸的原因。请你看一下好吗?谢谢你。

4

2 回答 2

2

我的解决方案如下:

$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++;
   }
 }
于 2012-07-16T10:15:06.953 回答
-1

也许这是一个开始?

$sql = "INSERT INTO abc (txt) VALUES ('".$str2."')";
于 2012-07-16T10:07:30.167 回答