Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1081375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:09:40+00:00 2026-05-16T22:09:40+00:00

Im loading an xml file with tweets and then adding it a to a

  • 0

Im loading an xml file with tweets and then adding it a to a Mysql database. Up to this point it works fine but id like to do a basic check on the url field to see if its already added in the database. If its in the database already id like to update the mention count else insert it as a new entry. Its a real newbie question but im struggling to get it working. Heres the code as it stands now:

<?php 

require_once('functions/functions.php');

$dbhost = '****';
$dbuser = '****';
$dbpass = '****';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

if($conn)
 {
    echo "Database Connection Successfull...<br /><br />";
 }

$dbname = '****';
mysql_select_db($dbname) or die('Couldnt connect to database table');

if($dbname)
{
    echo "Database ".$dbname." Selected..<br /><br />";
}

  $tweetmeme = "http://api.tweetmeme.com/stories/popular.xml?category=sports-soccer&count=30" ; 

  $xml = @simplexml_load_file($tweetmeme) or die ("no file loaded") ; 
  if($xml)
  {
    echo "Tweetmeme XML loaded with ".count($xml->stories->story)." stories in the file..<br /><br />";
  }
 if(get_magic_quotes_gpc())
 {
    echo "Magic Quotes is ON<br /><br />";
 }
 $count_insert=0;
 $count_update=0;

 //Select url and id and compare to the url being added
 $url_compare = mysql_query("SELECT id,url FROM ft_tweets");


 if($url_compare)
 {
    //echo_result($url_compare);
    echo mysql_num_rows($url_compare)." rows loaded.<br /><br />";
 }

 $url_compare = mysql_fetch_assoc($url_compare);

foreach($xml->stories->story as $story)
{
    $title=check_input($story->title);


    $url=check_input($story->url);

    $media_type=check_input($story->media_type);

    $created=check_input($story->created_at);

    $url_count=check_input($story->url_count);

    $comment_count=check_input($story->comment_count);

    $excerpt=check_input($story->excerpt);



    $sql = "INSERT INTO ft_tweets (title,url,media_type,created_at,mention_count,comment_count,excerpt) VALUES ($title,$url,$media_type,$created,$url_count         ,$comment_count,$excerpt)";


    $result = mysql_query($sql) or die(mysql_error());
    if($result)
    {
        //echo "added to database<br />";
        $count_insert++;
    }
}
echo $count_insert." Records added to the database<br /><br />";
$search=mysql_query("SELECT * FROM ft_tweets WHERE title LIKE '%liverpool%' OR excerpt LIKE '%lfc%'");
if($search)
{
    echo "<br /><br />Found tweets mentioning Liverpool";
}
//fetch 10 tweets from ft_tweets where liverpool or lfc is in the excerpt or the title and store it in a variable
//echo_result($search);
echo "<br />";
var_dump($search);
echo "<br />";
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:09:40+00:00Added an answer on May 16, 2026 at 10:09 pm

    Seems like you just need to check for a duplicate tweet first.

    $sql = "SELECT id FROM ft_tweets WHERE url = '" . mysql_real_escape_string( $url ) . "'";
    $duplicate = mysql_query( $sql );
    if ( mysql_num_rows( $duplicate ) > 0 ) {
      // some notice about duplicate tweet
      $count_duplicate++;
    } else {
      // insert the new
      $sql = "INSERT INTO...";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose i have an XML file, that i use as local database, like this):
I am loading an XML file then I will display the contents of it
I have a basic question. I am loading an XML file using the URLLoader
I'm loading an XML file with this method: public static String readTextFile(String fullPathFilename) throws
I am loading an XML file into SimpleXML. The SimpleXML file is then processed
While loading an XML file in SSIS using an XML source component , i
I am loading an XML file using jQuery $.get. after loading the content, i
I have a flash file that is loading data from XML file. After I
Here is part 1 of our problem (Loading a dynamically generated XML file as
I have descriptions being displayed within an XML document and then loading it into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.