Author Topic: PHP, MYSQL insert multiple variables  (Read 630 times)

0 Members and 1 Guest are viewing this topic.

Offline bellTopic starter

  • Irregular
  • Posts: 1
    • View Profile
PHP, MYSQL insert multiple variables
« on: March 15, 2010, 01:43:17 PM »
Hi, I am currently building a project that requires tweets to be stored in a database. I am using CURL to read the last 10 tweets (from the .xml file) and echo them on a page, I am also trying to store them in a database if they haven't already been added.

I can get the oldest tweet (from that set of 10) to store in the database, the rest won't.

Here is the code

$query01 = "SELECT * FROM tweets4";

$result01 = mysql_query($query01)or die(mysql_error());

while($row = mysql_fetch_array($result01)){
$latest_id = $row['tweet_id'];
echo '<p>'.$latest_id.'</p>';
}

If ($tweet_id <= $latest_id){
echo "Same number";
}
else {
mysql_query("INSERT INTO tweets4(tweet,tweet_id,user_name,user_id,user_img,time_info) VALUES
('".mysql_real_escape_string($tweet)."',
'$tweet_id',
'$user_name',
'$user_id',
'$user_img',
'$time_info') ")
or die(mysql_error());
}

Just wondering if you could advise me how to store multiple records in a database with one query?

Thanks in advance
« Last Edit: March 15, 2010, 01:46:05 PM by bell »

Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,444
  • Gender: Male
    • View Profile
Re: PHP, MYSQL insert multiple variables
« Reply #1 on: March 19, 2010, 08:39:51 AM »
Try a multi-valued INSERT statement.
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.