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

  • Home
  • SEARCH
  • 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

i have a table that have one column (AbsoluteUrl NVARCHAR(2048)) and i want to
Im sure this will be a simple one but have a project that started
I've been looking for a simple regex for URLs, does anybody have one handy
We have an app that uses simple one way binding with a GridView to
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
I have a simple question related to one-line programming. First an example: function test(a)
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I have a very simple class with only one field member (e.g. String). Is
I have a really simple class with two methods; One that will be called
I have a relatively simple form which asks a variety of questions. One of

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.