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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:38:32+00:00 2026-06-17T13:38:32+00:00

I have made the following script to check if an article exists in another

  • 0

I have made the following script to check if an article exists in another table, if it does it is supposed to echo that the article exists, if it doesnt it then adds the article id and article name to another table. The problem I am having is if I clear the workshoptabs table and run the update script it creates all the article id / names, but if I add a new article to the dbel6_content table and then run the update script again, it doesn’t add the new articles to the workshoptabs. Also if I delete a record from workshoptabs and run the script it doesnt re add it, but if I clear the whole table it re imports everything then.

$resultB = mysql_query("SELECT * FROM dbel6_content WHERE catid='12'") or die(mysql_error());  
while($rowB = mysql_fetch_array( $resultB )) {
  $articleid = $rowB['id'];
  $articlename = $rowB['title'];

  $resultA = mysql_query("SELECT * FROM workshoptabs WHERE articleid='$articleid'") or die(mysql_error());  
  while($rowA = mysql_fetch_array( $resultA )) {
    $articleexists = $rowA['articleid'];
    echo $articleexists.' Exists';
  }

  if (empty($articleexists)){
    mysql_query("INSERT INTO workshoptabs (articleid, articlename) VALUES ('$articleid', '$articlename')") or die(mysql_error()); 
    echo 'Added Articles : '.$articleid.'-';    
  }
}

If I run the script I get :
16 Exists17 Exists20 Exists24 Exists25 Exists26 Exists27 Exists34 Exists

If I wipe the workshoptabs table and reimport everything I get :
Added Articles : 16-Added Articles : 17-Added Articles : 18-Added Articles : 19-Added Articles : 20-Added Articles : 21-Added Articles : 22-Added Articles : 23-Added Articles : 24-Added Articles : 25-Added Articles : 26-Added Articles : 27-Added Articles : 34-

But if for example I now delete article 21 and run the script again it doesnt add it.

  • 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-17T13:38:33+00:00Added an answer on June 17, 2026 at 1:38 pm

    I suggest using the row count of your query to determine if a record exists:

    <?php
    
      $resultB = mysql_query("SELECT * FROM dbel6_content WHERE catid='12'") or die(mysql_error());
    
      while($rowB = mysql_fetch_array( $resultB )) {
    
        $articleid = $rowB['id'];
        $articlename = $rowB['title'];
    
        $resultA = mysql_query("SELECT * FROM workshoptabs WHERE articleid='$articleid'") or die(mysql_error());
    
        if (mysql_num_rows($resultA)>0) {
          // exists
          echo $articleid.' Exists';
        } else {
          // doesnt exist
          mysql_query("INSERT INTO workshoptabs (articleid, articlename) VALUES ('$articleid', '$articlename')") or die(mysql_error()); 
          echo 'Added Articles : '.$articleid.'-';  
        }
    
      }
    
    ?>
    

    Consider looking into PDO or MySQLi, as mentioned by Joseph.

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

Sidebar

Related Questions

I have made the following search script but can only search one table column
Does someone have already made a script as following examples with YUI dataTable ?
Currently I have this small script that makes it possible to check if a
I have the following script which changes a jquery made object's color to blue:
I have a PHP script using Doctrine 2 which does essentially the following: $entityManager->transactional(function($em)
I have made a script that is running as a 'Apps Script Gadget' in
I have made the following script to upload a csv and import it into
I have created a sitecollection and in AAM I have made following settings for
I have made the following regexp for extracting robots links: re.compile(r/\S+(?:\/+)) And i get
I have made a QMessageBox in the following way: msgBox.setText(Are you sure?); msgBox.setStandardButtons(QMessageBox::Yes| QMessageBox::No);

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.