 <pre><code>&lt;?php require './config.php'; require './facebook.php'; //connect to mysql database mysql_connect($db_host, $db_username, $db_password); mysql_select_db($db_name); mysql_query("SET NAMES utf8"); //Create facebook application instance. $facebook = new Facebook(array( 'appId' =&gt; $fb_app_id, 'secret' =&gt; $fb_secret )); $output = ''; $isHaveNext = false; if (isset($_POST['send_messages'])) { //default message/post $msg = array( 'message' =&gt; 'date: ' . date('Y-m-d') . ' time: ' . date('H:i') ); //construct the message/post by posted data if (isset($_POST['message'])) { $msg['message'] = $_POST['message']; } if (isset($_POST['url']) &amp;&amp; $_POST['url'] != 'http://') { $msg['link'] = $_POST['url']; } if (isset($_POST['picture_url']) &amp;&amp; $_POST['picture_url'] != '') { $msg['picture'] = $_POST['picture_url']; } // get offset $offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0; // get total rows count $query = mysql_query("SELECT COUNT(1) FROM offline_access_users LIMIT 1"); $rows = mysql_fetch_array($query); $total = $rows[0]; //get users and try posting our message/post $result = mysql_query("SELECT * FROM offline_access_users LIMIT 50 OFFSET $offset"); if ($result) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $msg['access_token'] = $row['access_token']; try { $facebook-&gt;api('/me/feed', 'POST', $msg); $output .= "&lt;p&gt;Posting message on '" . $row['name'] . "' wall success&lt;/p&gt;"; } catch (FacebookApiException $e) { $output .= "&lt;p&gt;Posting message on '" . $row['name'] . "' wall failed&lt;/p&gt;"; } } } // next if ( $total &gt; ($offset + 50) ) { $isHaveNext = true; $offset += 50; ?&gt; &lt;form action="" method="post"&gt; &lt;input type="hidden" name="message" value="&lt;?php echo $_POST['message'] ?&gt;"&gt; &lt;input type="hidden" name="url" value="&lt;?php echo $_POST['url'] ?&gt;"&gt; &lt;input type="hidden" name="picture_url" value="&lt;?php echo $_POST['picture_url'] ?&gt;"&gt; &lt;input type="hidden" name="offset" value="&lt;?php echo $offset ?&gt;"&gt; &lt;input type="submit" name="send_messages" value="Next"&gt; &lt;/form&gt; &lt;?php echo $output; } } if ($isHaveNext) exit(1); ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="et" lang="en"&gt; &lt;head&gt; &lt;title&gt;Batch posting&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;style type="text/css"&gt; body { font-family:Verdana,"Lucida Grande",Lucida,sans-serif; font-size: 12px} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Batch posting&lt;/h1&gt; &lt;form method="post" action=""&gt; &lt;p&gt;Link url: &lt;br /&gt;&lt;input type="text" value="http://" size="60" name="url" /&gt;&lt;/p&gt; &lt;p&gt;Picture url: &lt;br /&gt;&lt;input type="text" value="" size="60" name="picture_url" /&gt;&lt;/p&gt; &lt;p&gt;Message: &lt;br /&gt;&lt;textarea type="text" value="" cols="160" rows="6" name="message" /&gt;Message here&lt;/textarea&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" value="Send message to users walls" name="send_messages" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;?php echo $output; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Bonus:</strong> Use <a href="http://www.php.net/manual/en/pdo.connections.php" rel="nofollow">PDO</a> instead of mysql_* functions.</p>