테스트 사이트 - 개발 중인 베타 버전입니다

반복문을 돌릴때 특정 코드를 받으면 계속 돌아가게 하고 싶습니다. 채택완료

kujira 5년 전 조회 2,830

안녕하세요.

curl로 api를 호출을 반복문을 통해 여러번 돌리는 작업을 해야하는데요

한 번 호출시 api에서 rcode = 200이라는 값을 받아오는데

이 값을 받아야 다음 반복이 진행되도록 조건을 주려면 어떻게 해야되나요?

 

</p>

<p><?php

    include_once('./_common.php');</p>

<p>    $sql = "select * from test11";

    $rst = sql_query($sql);</p>

<p> </p>

<p>    if($decoded['rcode']=="200"){

        while($row = sql_fetch_array($rst)){

            $sct_addr = "TEST";

            $sender = "master";

            $recipient = $row['mb_id'];

            $amount = $row['Amount'];</p>

<p>            $curl = curl_init();</p>

<p>            curl_setopt_array($curl, array(

              CURLOPT_URL => "<a href="http://abc.com"," target="_blank" rel="noopener noreferrer">http://abc.com",</a>

              CURLOPT_RETURNTRANSFER => true,

              CURLOPT_ENCODING => "",

              CURLOPT_MAXREDIRS => 10,

              CURLOPT_TIMEOUT => 0,

              CURLOPT_FOLLOWLOCATION => true,

              CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

              CURLOPT_CUSTOMREQUEST => "POST",

              CURLOPT_POSTFIELDS =>"",

              CURLOPT_HTTPHEADER => array(

                "Content-Type: application/json"

              ),

            ));</p>

<p>            $response = curl_exec($curl);</p>

<p>            curl_close($curl);

            $decoded = json_decode($response, true);

            //print_r($decoded);

            echo $decoded['rcode'];

        }

    }else{

        echo "error";

        exit;

    }

?></p>

<p>

 

위와 같이 소스를 만들었는데요 if($decoded['rcode']=="200"){ 이렇게 조건을 주니 

맨 처음 시작할때가 문제더라구요;;;;;;

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
B
5년 전

</p>

<p><?php

    include_once('./_common.php');

    $sql = "select * from test11";

    $rst = sql_query($sql);

 

    while($row = sql_fetch_array($rst)){ // 이렇게 반복이고

        $sct_addr = "TEST";

        $sender = "master";

        $recipient = $row['mb_id'];

        $amount = $row['Amount'];

        $curl = curl_init();

        curl_setopt_array($curl, array(

          CURLOPT_URL => "<a href="http://abc.com"," target="_blank" rel="noopener noreferrer">http://abc.com",</a>

          CURLOPT_RETURNTRANSFER => true,

          CURLOPT_ENCODING => "",

          CURLOPT_MAXREDIRS => 10,

          CURLOPT_TIMEOUT => 0,

          CURLOPT_FOLLOWLOCATION => true,

          CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

          CURLOPT_CUSTOMREQUEST => "POST",

          CURLOPT_POSTFIELDS =>"",

          CURLOPT_HTTPHEADER => array(

            "Content-Type: application/json"

          ),

        ));

        $response = curl_exec($curl);

        curl_close($curl);

        $decoded = json_decode($response, true);

        //print_r($decoded);

        echo $decoded['rcode'];</p>

<p>        // 건별로 rcode값 확인해서</p>

<p>        if($decoded['rcode']=='200'){</p>

<p>            // 원하는 동작</p>

<p>        } else {</p>

<p>            // 자. 200이 아니면, 무엇을 하길 원하나요? 200 떨어질 때까지 재시도?</p>

<p>        }

    }

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인