-3

I'm Getting the popular tweets by this link

https://api.twitter.com/1.1/search/tweets.json?q=('[]')&lang=en&result_type=popular&count=100

And I use this code to import tweet data to database

    mysql_query('SET NAMES \'utf8\''); 
mysql_query("INSERT INTO Tweets (id,username,name,tweet,media) VALUES('$id','$uname','$jname','$twitt','$mida')") 
or die(mysql_error()); 

($id , $username and other variables work well and have no problem.) You can see the twitter link, It Gets 100 popular tweets but the code i used to import data to database just sends the latest result of it (latest popular tweet) Now my question is that How can I Import all 100 tweets to database at the same time? I'm using php

Ali
  • 67
  • 1
  • 7
  • 2
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 10 '17 at 17:09
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***. Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jan 10 '17 at 17:09
  • now security is not important. could you please help me with my problem? – Ali Jan 10 '17 at 17:13
  • I hate when people say *"I'm not that far along..."* or *"This site will not be public..."* or *"It's only for school, so security doesn't matter..."*. If teachers and professors are not talking about security from day one, they're doing it wrong. Challenge them. They're teaching sloppy and dangerous coding practices which students will have to unlearn later. I also hate it when folks say, *"I'll add security later..."* or *"Security isn't important now..."* or *"Ignore the security risk..."*. If you don't have time to do it right the first time, when will you find the time to add it later? – Jay Blanchard Jan 10 '17 at 17:25
  • no user or people will see my codes !!! – Ali Jan 10 '17 at 17:48
  • it just gets tweets and sends them to telegram! and no body will see the code or source! – Ali Jan 10 '17 at 17:49

1 Answers1

0

I'll give you a hint.

// inserts 1 record.
mysql_query("INSERT INTO Tweets (id,username,name,tweet,media) VALUES('$id','$uname','$jname','$twitt','$mida')") 

// inserts 2 records.
mysql_query("INSERT INTO Tweets (id,username,name,tweet,media) VALUES('$id','$uname','$jname','$twitt','$mida')") 
mysql_query("INSERT INTO Tweets (id,username,name,tweet,media) VALUES('$id2','$uname2','$jname2','$twitt2','$mida2')") 

Now before you make 100 lines of code with insert statements, you need to use a for-loop to insert each one.

Dellowar
  • 3,160
  • 1
  • 18
  • 37
  • thanks for helping but for example the code : `$twitt = $tweet->full_text;` gets the tweet text and when you run `echo $twitt;` it shows you 100 tweets. when it show one tweet that you change `&count=100` to `&count=1`. – Ali Jan 10 '17 at 17:18
  • @Ali Then you must find a way to parse `$twitt` into an array, that way you can use a loop. I predict that the tweets are delimited by a character -- perhaps a new line ("\0") -- in that case you must invoke `$array = explode("\0", $twitt)` – Dellowar Jan 10 '17 at 17:21
  • I don't PHP!! could you please help me by the code? all the code is here https://limoo.cf/harf.zip – Ali Jan 10 '17 at 17:29
  • "no user or people will see my codes !!!" "no body will see the code or source" -- Ali – spencer7593 Jan 10 '17 at 19:00