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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:54:47+00:00 2026-05-28T02:54:47+00:00

MySQL double while loop in php: $geta=mysql_query(SELECT id FROM table1 WHERE id<50); while($row=mysql_fetch_array($geta)){ while($row2=mysql_fetch_array($geta)){

  • 0

MySQL double while loop in php:

$geta=mysql_query("SELECT id FROM table1 WHERE id<50");
while($row=mysql_fetch_array($geta)){
while($row2=mysql_fetch_array($geta)){
$id1=$row['id'];
$id2=$row2['id'];
echo "$id1 and $id2";
}
}

I’m trying to make every possible combination of id with another id.

Not sure what is wrong with it…output is just a list of id1…

What am I doing wrong here?

  • 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-28T02:54:47+00:00Added an answer on May 28, 2026 at 2:54 am

    Each time you call mysql_fetch_array(), you fetch the next result from the same result set from the MySQL database. So calling it twice in an outer and inner loop just advances the record pointer.

    In your case, you should load all results to a single array first, then iterate over that:

    // Array to hold all results
    $results = array();
    $geta = mysql_query("SELECT id FROM table1 WHERE id<50");
    while($row = mysql_fetch_array($geta)){
      // Append all rows to the array
      $results[] = $row;
    }
    
    // Now iterate over your array $results in the outer & inner loops
    foreach ($results as $r1) {
      foreach ($results as $r2) {
        echo "$r1  and $r2";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MySQL Doubles my results? mysql_select_db(db, $con); $result = mysql_query(SELECT * FROM cart_products WHERE cart_id=22);
mysql> select count(*) from table where relation_title='xxxxxxxxx'; +----------+ | count(*) | +----------+ | 1291958
I'm using this fputcsv code: $result = mysql_query('SELECT * FROM `mash`'); if (!$result) die('Couldn\'t
When selecting from a MySQL table in PHP the results are always strings. Is
I have one PHP script inserting rows in a MySQL database. Each row has
Reason why: http://bugs.mysql.com/bug.php?id=61933 I recompiled the connector from source, incremented tit a version to
I have a php script to retrieve data from a MysQL databse following an
Can someone suggest me a good example or link to select records from MySQL
For some reason, my mysql table is converting single and double quotes into strange
solved: IstBestellwert = grouped.Sum(o => (double)o.SollMenge * (double)o.Preis) works My SQL Statment SELECT ABId,

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.