当前位置: 动力学知识库 > 问答 > 编程问答 >

php - how to import some data to database table at the same time?

问题描述:

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

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: