Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The code below is only sending one variable to my script but it is running trough the loop as normal. I would appreciate some help with this. Thank You.

<?php    
$result = mysql_query("SELECT * FROM users WHERE id =$id");         
    while($row = mysql_fetch_assoc($result)){

        //$user_phone = $row['phone'];
        $phone = $row['email'];
        $email = $row['phone'];

        $url = 'http://example.com/request.php?phone='.$phone.'&email='.$email.'';
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_TIMEOUT => '5'
        ));
        $resp = curl_exec($curl);
        curl_close($curl);
    }

?>
share|improve this question
add comment

1 Answer

I think try to seperate curl statement from the loop.

<?php    
  $result = mysql_query("SELECT * FROM users WHERE id =$id");         
  while($row = mysql_fetch_assoc($result)){

  //$user_phone = $row['phone'];
  $phone = $row['email'];
  $email = $row['phone'];
  $url = 'http://example.com/request.php?phone='.$phone.'&email='.$email.'';
  call_curl($url);
  }
 ?>

    function call_curl($url){
     $curl = curl_init();
     curl_setopt_array($curl, array(
     CURLOPT_URL => $url,
     CURLOPT_TIMEOUT => '5'
     ));
     $resp = curl_exec($curl);
     curl_close($curl);
    }
share|improve this answer
    
That worked great Amir really appreciate your help, thank you. –  cusackBOOM Apr 26 '13 at 12:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.