<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Comments on snippet: 'Save tweets using PHP from the twitter search API to a MySQL database'</title>
<link>http://snipplr.com</link>
<description>Snipplr comments feed'</description>
<language>en-us</language>
<pubDate>Mon, 20 May 2013 01:48:55 GMT</pubDate>
<item>
<title>kso said on 8/7/12</title>
<link>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</link>
<description><![CDATA[ Dear,

     plz advice why i'm getting this error ?

Warning: Invalid argument supplied for foreach() in /home/kso/public_html/get_tweet.php on line 27

please find my code and let me know where is the mistake.

apprecite your feedback....


$username='hangover_2011'; // set user name
$format='json'; // set format



$q = $_GET["q"]; // query string
$request = "http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}".urlencode($q);
$response = file_get_contents($request);
$jsonobj = json_decode($response);



if($jsonobj != null){

	$con = mysql_connect($host, $userdname, $password);

	if (!$con){
		die('Could not connect: ' . mysql_error());
	}


foreach ($jsonobj->results as $status) {

     $text = mysql_real_escape_string($item->text);
     $created_at = $status->created_at;
     $created_at = strtotime($created_at);
     $mysqldate = date('Y-m-d H:i:s',$created_at);    
     $profile_image_url = mysql_real_escape_string($item->profile_image_url);

     $screen_name = $status->user->screen_name;
     
     $query = mysql_real_escape_string($query);

		mysql_select_db($database, $con);
                // SQL query to create table available at http://snipplr.com/view/56995/sql-query-to-create-a-table-in-mysql-to-store-tweets/
                
		$query = "INSERT into tweets (`tweet_id`,`text`,`screen_name`,`created_at`,`q`) VALUES ('','$text','$screen_name',' $created_at','$q')";
		
		$result = mysql_query($query);
		



}

mysql_close($con);
} ]]></description>
<pubDate>Tue, 07 Aug 2012 08:40:28 GMT</pubDate>
<guid>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</guid>
</item>
<item>
<title>JustinN said on 3/12/12</title>
<link>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</link>
<description><![CDATA[ @skavhellen - which version of MySQL have you got installed? You need 5.2 or above as this script makes use of the json_decode function. ]]></description>
<pubDate>Mon, 12 Mar 2012 11:08:27 GMT</pubDate>
<guid>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</guid>
</item>
<item>
<title>skavhellen said on 12/4/11</title>
<link>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</link>
<description><![CDATA[ Can't seem to get this one to work with the database.
I get now error and no data in the database.

I've configured it with my own database information but nothing happens when I open this file in a browser window.
Am I missing something?

Hope for some help here :) ]]></description>
<pubDate>Sun, 04 Dec 2011 09:34:19 GMT</pubDate>
<guid>http://snipplr.com/view/56994/save-tweets-using-php-from-the-twitter-search-api-to-a-mysql-database/</guid>
</item>
</channel>
</rss>