2013-06-23 8 views
0

나는이 작업을 어떻게 얻는 지 잘 모르겠다. 나는 twitteroauth.php 라이브러리를 사용하고 있으며 db 쿼리에서 사용자 토큰과 토큰 비밀을 얻고 있습니다.루프에서의 재 선언 기능

while($row = mysql_fetch_array($m)) 
{ 
    $connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret); 
    $consumerKey = "#####"; 
    $consumerSecret = "#####"; 
    $oauthToken = $row['oauth_token']; 
    $oauthTokenSecret = $row['oauth_token_secret']; 
    $userName = $row['username']; 

    $query = mysql_query("select url from retweets order by rand() limit 1"); 
    $row = mysql_fetch_assoc($query); 
    $retweet = basename($row['url']); 

    $method = 'statuses/retweet/'.$retweet.''; 
    twitterOAuth($method, $connection->post($method), $connection->http_code, $userName); 
} 

MySQL의 여러 결과가있는 경우, 그것은을 통해 루프를 다음과 같이 말한다 : 여기에 코드입니다

Fatal error: Cannot redeclare random_from() (previously declared in /usr/share/nginx/www/twitteroauth/twitteroauth.php:199) in /usr/share/nginx/www/twitteroauth/twitteroauth.php on line 199 

$connection 변수는 MySQL의 쿼리에서 $oauthToken$oauthTokenSecret에 의존하기 때문에, 나는 '수 루프 바깥으로 옮기지 마십시오. 어떻게 다시 작성하지 않고 루프마다 사용할 수 있습니까?

미리 감사드립니다.

업데이트 :이 twitterOAuth

function twitterOAuth($method, $response, $http_code, $userName, $parameters = '') { 
     if($http_code == 200){ 
      echo "retweeted successfully @".$userName."<br />"; 
     }else{ 
      echo "an error has occurred while retweeting @".$userName.""; 
      echo "<br />"; 
      print_r($response); 
     } 
} 
+1

대신 'TwitterOAuth'를 수정해야합니다. 다시 말하면 재 선언이 발생합니다. – mario

+0

lib에 익숙하지 않지만 단일 연결 객체를 선언하고 각 반복마다 해당 속성을 변경하십시오. – GabeIsman

+0

'twitterOAuth' 기능은 어떻게 생겼습니까? –

답변

0

그것은 다음과 같이해야합니다 ...

당신은 당신이 그것으로 통과하고 싶었다 변수를 선언하기 전에 선언했다
while($row = mysql_fetch_array($m)) 
{ 

$consumerKey = "#####"; 
$consumerSecret = "#####"; 
$oauthToken = $row['oauth_token']; 
$oauthTokenSecret = $row['oauth_token_secret']; 
$userName = $row['username']; 

$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthTokenSecret); 

$query = mysql_query("select url from retweets order by rand() limit 1"); 
$row = mysql_fetch_assoc($query); 
$retweet = basename($row['url']); 
$method = 'statuses/retweet/'.$retweet.''; 

twitterOAuth($method, $connection->post($method), $connection->http_code, $userName); 
} 

입니다 ...

+0

왜 downvote? – KyleK

+0

같은 것을 그 아래로 옮겼습니다. – nick