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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:25:43+00:00 2026-05-15T02:25:43+00:00

I have one simple table. the primary key column name is id. I have

  • 0

I have one simple table. the primary key column name is id. I have almost 200 records and some how I deleted some of the records. Now the id column has following entries

1
2
4
5
6
8
9

Can any body tell me what query can I write that return me all the missing rows? For example 3,7 rows in above example. Or any PHP function that do that?

  • 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-15T02:25:44+00:00Added an answer on May 15, 2026 at 2:25 am
    <?php
    
    // CONNECT TO YOUR DB
    
    $missingRecords = array(); //<-- array you'll store your missing records
    $resultsArray = array(); //<-- log the good results
    $count = 0;
    $lastResult = 0;    
    
    $query = "SELECT * FROM `your_table`";
    $results = mysql_query($query);
    
    // populate the results array with your existing id #'s
    while($data = mysql_fetch_assoc($results)){
       array_push($resultsArray,$data['id']);
       $lastResult = $data['id'];
    }
    
    
    // cross check the id number with the iterator.  if no matches come up push the missing array
    for($i=0;$i<$lastResult;$i++){
        if(cross_check($resultsArray[$i])){
            $count++;
        }else{
            array_push($missingRecords, $count); 
            $count++;
        }
    }
    
    // function to cross check iterator and result array id number
    function cross_check($id){
        global $count;
        global $resultsArray;
        for($i=0;$i<count($resultsArray);$i++){
            if($resultsArray[$i] == $count){
                return true;
            }
        }
        return false;
    }
    
    // print out the missing records
    for($i=1;$i<count($missingRecords);$i++){
        echo 'Missing Record: ' . $missingRecords[$i] . '<br>'; 
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a fairly big DB (~200 tables) which almost entirely uses composite primary
So I have a table: CREATE TABLE TABLE_NAME ( COLUMN_1 char(12) NOT NULL, COLUMN_2
I'm new to programming so forgive my simple questions. Basically, I have two different
I am trying to import data from a large database. I have two tables
Given the following example (departments - projects): A department has the following properties (composite
First of all, sorry if this might be a stupid question. I'm very new
I’m hoping somebody will be able to help with my SQLite database problem. I’m
I hope I'm not being too long winded in this question, I just want
I've recently had to work with an application where most tables don't reference each
Probably a trivial question, but I want to get the best possible solution. Problem:

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.