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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:01:04+00:00 2026-05-27T06:01:04+00:00

I have two while loops running one after the other (not inside of each

  • 0

I have two while loops running one after the other (not inside of each other) – I’ve simplified the code a bit so that only the important parts of it are listed below. The problem arises when I compare the two echoed queries because the 2nd while loop apparently isn’t running at all.

I read somewhere that someone got around the problem by using a for loop for the second one but I want to get down to why exactly the second while loop is not running in my code.

$query_work_title = "SELECT title FROM works WHERE ";
while ($row = mysql_fetch_assoc($result_work_id)) {
    $query_work_title .= "OR '$work_id' ";
}
echo $query_work_title;
echo '<br />';
$result_work_title = mysql_query($query_work_title) or
    die(mysql_error($cn));

// retrieve the authors for each work in the following query
$query_author_id = "SELECT author_id FROM works_and_authors WHERE ";
while ($row = mysql_fetch_assoc($result_work_id)) {
    $query_author_id .= "work_id = 'hello' ";
}
echo $query_author_id;
  • 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-27T06:01:04+00:00Added an answer on May 27, 2026 at 6:01 am

    The MySQL extension keeps track of an internal row pointer for each result. It increments this pointer after each call to mysql_fetch_assoc(), and is what allows you to use a while loop without specifying when to stop. If you intend on looping through a result set more than once, you need to reset this internal row pointer back to 0.

    To do this, you would mysql_data_seek() after the first loop:

    while ($row = mysql_fetch_assoc($result_work_id)) {
        $query_work_title .= "OR '$work_id' ";
    }
    mysql_data_seek($result_work_id, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple while loops in my program that I feel ought to
I have two models: Show and Venue . Show has one venue while each
I have two applications written in Java that communicate with each other using XML
I currently have a Python 2.6 piece of code that runs two loops simultaneously.
I have two begininer programs, both using the 'while' function, one works correctly, and
I want to merge two branches that have been separated for a while and
I currently have my project running two separate threads (one for MFC operations, like
I have a class that has two method in it, one calls a class
I have two arrays built while parsing a text file. The first contains the
I have a query to select from another sub-query select. While the two queries

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.