2013-10-10 3 views
0

보다는 당신에게 내가 할 시도하고 잘못, 난 그냥 아래의 질문을 여기에 당신에게 코드를 제공 할 것이다 가지고있는 모든 방법을 ... 보여주는WHILE 문 동안 결과를 삭제

<?php 

$con = mysql_connect($db_server_name, $db_username, $db_password); 
if (!$con) { 
    echo "0"; 
} 
mysql_select_db("" . $db_database_name . "", $con); 
$result = mysql_query("SELECT * FROM sched_posts 
WHERE user_id='$user_id'"); 

while ($row = mysql_fetch_array($result)) { 
    $post_id  = $row['ID']; 
    $post_year = $row['post_year']; 
    $post_month = $row['post_month']; 
    $post_day  = $row['post_day']; 
    $post_hour = $row['post_hour']; 
    $post_minute = $row['post_minute']; 
    $post_privacy = $row['post_privacy']; 
    $post_message = $row['post_message']; 

    $current_date_time = date('Y-m-d H:i'); 
    $sched_format  = "$post_year-$post_month-$post_day $post_hour:$post_minute"; 
    echo "$current_date_time"; 
    echo "<br>"; 
    echo "$sched_format"; 
    echo "<br>"; 
    if ($current_date_time >= $sched_format) { 
     $attachment = array(
      'message' => '' . $post_message . '', 
      'name' => 'Title', 
      'source' => 'http://www.youtube.com/e/2raioEC7Hms', 
      'privacy' => array(
       'value' => '' . $post_privacy . '' 
      ), 
      'caption' => "Caption", 
      'link' => 'https://apps.facebook.com/something/', 
      'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent suscipit pharetra mauris in fringilla. Cum sociis natoque penatibus et magnis dis parturient montes.', 
      'description' => 'Description', 
      'picture' => 'http://gailbottomleyonline.com/wp-content/uploads/2012/06/facebook-schedule.jpg', 
      'actions' => array(
       array(
        'name' => 'Google', 
        'link' => 'http://www.google.com' 
       ) 
      ) 
     ); 
     // To authenticated user's wall 
     $result  = $facebook->api('/me/feed/', 'post', $attachment); 
    } else { 
     // Do Nothing 
    } 
} 
?> 

코드는 예약 된 페이스 북 게시물을 검색하여 현재 날짜 및 시간과 일치하는 경우 (또는 그 이전 인 경우) 게시합니다. 하지만 내가하고 싶은 일은 게시 될 때마다 개별 예약 된 게시물을 데이터베이스에서 삭제하는 것입니다.

내가 알고 싶은 것은,이 코드의 모든 부분에서 예약 된 게시물을 게시 한 후 즉시 업데이트되도록 허용하는 코드를 게시하는 곳입니다.

나는 POST라는 단어를 여러 번 사용했기 때문에 그렇게 혼란스럽지 않았 으면 좋겠다. 그러나 나는 당신이 아이디어를 얻길 바랍니다.

나는 여러 가지 다른 방법을 시도했지만 데이터베이스에서 게시물을 삭제하지 않거나 단순히 오류가 발생합니다.

위의 코드를 테스트 한 결과,이 부분은 문제가 없습니다. 오류는 내가 코드를 추가하여 데이터베이스에서 해당 게시물을 삭제하려고 할 때만 발생합니다.

은 지난 며칠 동안 다른 것을 시도해 왔습니다.

답변

0

페이스 북 서버에서 오류/예외가 발생하지 않는 경우에만 데이터베이스에서 항목을 삭제하십시오. 다음과 같이하십시오.

try 
{ 
    $result = $facebook->api('/me/feed/', 'post', $attachment); 
    // Delete the entry from database 
} 
catch(FacebookApiException $e) 
{ 
    $result = $e->getResult(); 
    error_log(json_encode($result)); 
} 
+0

글쎄요. 아직 잃어 버렸습니다. 나는 페이스 북 서버가 내 서버의 데이터베이스 결과와 어떤 관련이 있는지 전혀 모른다. – user2284703

+0

당신은 날 잡았어. 페이스 북에 게시 할 때 오류가 발생하면 API 호출 직후에 catch()에 걸리게됩니다. api 호출 후, 귀하의 항목 (귀하의 질문입니다)을 삭제하십시오. 위 코드를 시도 했습니까? –

+0

코드를 시도했지만 fb가 오류를 발견하지 못하고 파일이 삭제되지 않습니다. 붙여 넣은 코드는 내 데이터베이스의 결과를 가져오고 게시 할 준비가 된 것만 게시합니다. 그렇다면 그들은 그것들을 잘 게시합니다. 오류를 일으키지 않아서 잡히지 않습니다. – user2284703