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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:43:50+00:00 2026-05-23T01:43:50+00:00

Please consider the following: $query = SELECT legIDs FROM trip; $result = mysql_query($query) or

  • 0

Please consider the following:

$query = "SELECT legIDs FROM trip";
$result = mysql_query($query) or die("SELECT TRIPS ERROR: " . mysql_error());
while($row = mysql_fetch_assoc($result) or die("fetch error " . mysql_error())) {
    echo "<div style=\"border: 1px solid blue;float:left;\">Trip: <div style=\"float:right;\">";
    $legID = explode(",", $row['legIDs']);
        foreach($legID as $leg) {
            $query = "SELECT dep, arr FROM leg WHERE `Key` = " . $leg;
            $result = mysql_query($query) or die("SELECT LEGS ERROR: " . mysql_error());
            $row2 = mysql_fetch_assoc($result) or die("FILL ARRAY ERROR: " . mysql_error());
            echo $row2['dep'] . " - " . $row2['arr'] . "<br />";
    }
    echo "</div></div>";
}

For some reason this only returns one result, even when there are several values returned from the WHILE() loop. The FOREACH() loop works on the one row that’s returned. Am I doing something wrong to only have this return one row? Performing the query contained in $result directly on the server returns several rows.

  • 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-23T01:43:51+00:00Added an answer on May 23, 2026 at 1:43 am

    You’re using $result twice in the inner and outer loops.. When the inner loop completes, $result will be an “empty” result set, so the outer loop will terminate. CHange the inner loop to $result2 and things should be fine.

    However, since the inner loop is simply fetching more results based on what the outer loop produces, you should consider rewriting it as a joined query. It’s almost always more efficient to run a single “large result” query, than a long series of “small result” individual queries. You end up with fairly hefty overhead to parse/compile each of the inner queries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following SQL Server 2005/2008 query: Select [UID], [DESC] From SomeTable Order By
Please consider the following HTML: <input type='text' id='name'/> <option id='option'> <select value='1'>hi</select> <select value='2'>bye</select>
Please consider the following: <td style=width: 500px;> <div style=width: 400px;>SomeContent</div> </td> For some reason,
Please consider the following fork() / SIGCHLD pseudo-code. // main program excerpt for (;;)
Please consider the following scenario: map(T,S*) & GetMap(); //Forward decleration map(T, S*) T2pS =
Please consider the following simple use case: public class Foo { public virtual int
Please consider the following: DECLARE @xml XML SET @xml = '<Capture> <Data><DataType>Card Number</DataType><Value>1234567898765</Value></Data> <Data><DataType>Expiry
please consider the following scenario for .net 2.0: I have an event that is
Please consider the following code. enum type {CONS, ATOM, FUNC, LAMBDA}; typedef struct{ enum
Please, consider the following (I'm sorry for the amount of code; but this is

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.