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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:13:07+00:00 2026-06-17T21:13:07+00:00

I am staring into this one for hours. I am not able to find

  • 0

I am staring into this one for hours. I am not able to find the mistake. Can anyone tell me what wrong did I do? Or is there a better way to compare?

$res1=mysql_query(**query for table1**);
$n1=mysql_num_rows($res1);
$res2=mysql_query(**query for table 2**);
$n2=mysql_num_rows($res2);

for($i=0;$i<$n1;$i++)
{
    $r1=mysql_fetch_row($res1);

    for($j=0;$j<$n2;$j++)
    {
        $r2=mysql_fetch_row($res2);
        if($r1[0]==$r2[0])
        {
            echo $r1[0]."<br>";
        }
    }
}

table 1 contains these elements: 1,2,3,16,18,19,20,21,22,24,23
table 2 contains : 23,21

However, the program returns zero matches. Why?

  • 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-17T21:13:08+00:00Added an answer on June 17, 2026 at 9:13 pm

    So what is happening here is

    1. you are looping over all hte elements of result 1 correctly, but you a re not looping over all the elements of result two correctly.

    The result two elements are getting exhausted in the first iteration.

    from the example data you have posted, here is the looping:

    when r1 is 1,

    r2 is 23,21

    when r1 is 2,

    r2 is exhausted.

    To reset result two again, you will have to do

    mysql_data_seek($res2,0);
    each time

    i.e your for loop will look like this

    for($i=0;$i<$n1;$i++) {
    
        $r1=mysql_fetch_row($res1);
    
        mysql_data_seek($res2,0);
        for($j=0;$j<$n2;$j++)     {
            $r2=mysql_fetch_row($res2);
            if($r1[0]==$r2[0])         {
               echo $r1[0]."<br>";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone ever run into this issue before? Sometimes the string displays, sometimes half
So I've been trying to insert sql into this one specific table for the
I have searched for hours but could not find anything similar. The crash has
Tricky one to explain this but could be an interesting challenge to find the
I have been staring at this code for hours now and I cannot figure
i want to convert this string into DateTime. Tue Aug 19 15:05:05 +0000 2008
Please help me somebody to convert unicodestring into string This is how i am
Could someone please help me to convert this String into a Map ... String
I'm trying to turn this XML string into a select I have @Schedule XML
i have this code i found to cut a string into words. i cant

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.