Results 1 to 7 of 7
Thread: Inserting an array into MySQL
Feb 13, 2012, 19:25 #1
- Join Date
- Nov 2011
- 0 Post(s)
- 0 Thread(s)
Inserting an array into MySQL
I am trying to put some JSON from the twitter REST API into a SQL database. My goal is to be able to look up account information from multiple accounts in one fell swoop.
I have been successful in echoing out the right data, but am not able to write it to the database.
I have a feeling there is something wrong with my array, specifically that each account I am looking up is in an array that does not share a common key, something like:
Array ( [*twitterhandle being used as the key*] => Array ( [screen_name] => value [name] => value [image] => value [following] => value [listed] => value [followers] => value [tweets] =>value ) [*a different twitter handle being used a key*]...
Her's the code that I am using:
$result = mysqli_query($link,
twitterhandle FROM accounts");
while ($row = mysqli_fetch_assoc($result)) //build an array of the twitter handles in the "accounts" table in the database
foreach ($handles as $handle) //loop each handle as a twitter api Query grabbing the following JSON array
$url = file_get_contents('http://api.twitter.com/1/users/show.json?screen_name='.$handle.'&include_entities=true');
$json_a = json_decode($url, true);
'tweets'=>$json_a['statuses_count']); //try to echo to see if it works, should go and grab field 'owner' from JSON file
$sql = "UPDATE accounts SET
account_owner='it works' //just using this as to focus on getting the WHERE clause to work
WHERE twitterhandle='$?'"; //not sure what to put here. i have tried several things but nothing works. The best I can do is get the last set of results in my array.
$error = 'Error adding twitter data. ' . mysqli_error($link);