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 8965061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:43:52+00:00 2026-06-15T16:43:52+00:00

I have following code: foreach($RSS_DOC->channel->item as $RSSitem) { $item_id = md5(str_replace(array(‘\”, ”), ”, $RSSitem->title));

  • 0

I have following code:

foreach($RSS_DOC->channel->item as $RSSitem) {

    $item_id    = md5(str_replace(array('\'', '"'), '', $RSSitem->title));
    $fetch_date = date("Y-m-j G:i:s"); //NOTE: we don't use a DB SQL function so its database independant
    $item_title = str_replace(array('\'', '"', '(', ')', ' - ', '.'), '', $RSSitem->title); 
    $item_date  = date("Y-m-j G:i:s", strtotime($RSSitem->pubDate));
    $item_url   = $RSSitem->link;

    $words = explode(' ', $item_title);

    echo "Processing item '" , $item_id , "' on " , $fetch_date     , "<br/>";
    echo $item_title, " - ";
    echo $item_date, "<br/>";
    echo $item_url, "<br/>";

    // Does record already exist? Only insert if new item...

    $item_exists_sql = "SELECT item_id FROM rssingest where item_id = '" . $item_id . "'";
    $item_exists = mysql_query($item_exists_sql, $db);
    if(mysql_num_rows($item_exists) < 1) {

        echo "<font color=green>Inserting new item..</font><br/>";
        $item_insert_sql = "INSERT INTO rssingest(item_id, feed_url, item_title, item_date, item_url, fetch_date) VALUES ('" . $item_id . "', '" . $feed_url . "', '" . $item_title . "', '" . $item_date . "', '" . $item_url . "', '" . $fetch_date . "')";
        $insert_item = mysql_query($item_insert_sql, $db);

        foreach ($words as $value) {

            $word_exists_sql = "SELECT id FROM words WHERE word = '" . $value . "'";
            $word_exists = mysql_query($word_exists_sql, $db);

            if (mysql_num_rows($word_exists) < 1) {
                $word_insert_sql = "INSERT INTO words(word, count) VALUES ('" . $value . "', '1')";
                $insert_word = mysql_query($word_insert_sql, $db);
                echo "<font color=green>Inserting word ".$value."..</font><br/>";

            } else {
                $word_update_sql = "UPDATE words SET count = count+1 WHERE word = '" . $value . "'";
                $update_word = mysql_query($word_update_sql, $db);
                echo "<font color=green>Updating count for word ".$value."..</font><br/>";
            }
        }



    } else {
        echo "<font color=blue>Not inserting existing item..</font><br/>";
    }

    echo "<br/>";
}

The first foreach works as expected, the second one only inserts the first word of the first rss item in the DB, even though the echo’s for the rest of the words are displayed correctly.

What am I missing?

  • 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-06-15T16:43:53+00:00Added an answer on June 15, 2026 at 4:43 pm
    $word_insert_sql = "INSERT INTO words(word, count) VALUES ('" . $value . "', count+1)";
    

    Where exactly is that count + 1 supposed to be coming from. Surely that should just be 1.

    In any case, where you’re attempting DB operations, it’s usually a good idea to check that they’ve worked before continuing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code foreach (var rssItem in rss.Channel.Items) { // ... }
I have the following code: foreach (ListItem item in check.Items) { if (item.Selected) {
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following smarty code: {foreach from=$additional_fields item=v} {if $v.fieldid eq 5} {php}
I have following code: <?php $select_options = array(); foreach($delivery_options as $option) { $select_options[$option->getDeviceId()] =
I have an array, which I am using the following code: foreach ($taglist as
I have the following code: foreach ($model->details as $detail) { if ($detail->Title) echo $detail->Title;
I have a following code: foreach (ListItem item in lstCreate.Items) { if (item.Selected) strCreateNewVideoCategory
This is a quick one. I have the following code: foreach (var item in
I have the following code @foreach (var item in Model.Defaults) { <tr class=CertainCategory> <td>

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.