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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:42:48+00:00 2026-06-18T09:42:48+00:00

i am having a nonsense problem with php. The first loop is supposed to

  • 0

i am having a “nonsense” problem with php. The first loop is supposed to get a certain record from the table and compare it to all the record in the second table…

So i expected it to print 41 “2nd”‘s after every “1st”‘s. Since there are 41 records in the second table. But instead the while loop works the first time and ignores the second while loop afterwards.

The result i get:

1st2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd2nd1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st1st…

while($row = mysql_fetch_array($select))
{
    echo "1st";
    while($row2 = mysql_fetch_array($select2))
    {
        echo "2nd";
        $string = $row2["header"];
        $find = $row["email"];
        if(strstr($string, $find)) {
            $email = $row["email"];
            echo "found it";
        } else {
            //no email found
        }
    }
}
  • 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-18T09:42:49+00:00Added an answer on June 18, 2026 at 9:42 am

    You need to execute second query before entering inner loop:

    
        while($row=mysql_fetch_array($select))
        {
            echo "1st";
    
            $select2 = mysql_query("select ...");
    
            while($row2=mysql_fetch_array($select2))
            {
    
    

    Better yet is to run second query before starting the first loop, and save records to another array. Then you can avoid n^2 queries:

    
        $emailToRecord = array();
        $select2 = mysql_query("select ...");
        while($row2=mysql_fetch_array($select2)) {
           $emailToRecord[$row2["header"]] = $row2;
        }
    
        while($row=mysql_fetch_array($select))
        {
            echo "1st";
            $find = $row["email"];
            if (isset($emailToRecord[$find])) {
                   echo "found it";
            }
        }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got several rails 3.1 apps, and I'm having this problem in all of
Having just added a new button in my web application, I get an error
Having trouble understanding how to filter an images table by tag information in a
I seem to be having problems using ggplot2. I get the following error while
Having the following code to draw circle (taken from Google Play Services maps sample):
Having just moved from textmate to vim I'm curious. To be able to navigate
Having a weird problem here. Everybody knows that if you use web.config's customErrors section
I am attempting to solve a problem from topcoder.com and it's driving me crazy.
Having what seems to be a basic problem in Powershell. I am doing a
Having specified table cell width <td style=width:100px> when content width is more than 100px

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.