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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:27:27+00:00 2026-05-13T15:27:27+00:00

Riddle me this… in the while($row = mysql_fetch_assoc($result) and $runningOK) loop, if the PHP

  • 0

Riddle me this… in the while($row = mysql_fetch_assoc($result) and $runningOK) loop, if the PHP && operator is used in place of the and then mysql_fetch_assoc fails terribly and returns just the number 1 when running.

I’ve tried mysql_fetch_array() and in place and I still have the 1 problem. It is when, and only when, I replace the && with an and like the current while statement that the correct rows are returned.

I had placed debug statements before, inside, and after to insure this. I would like to know if this is a PHP quirk or something I couldn’t account for.

// Query
$selectQuery = "SELECT * FROM jobs_cache LIMIT 20";
// Run the Selection Query.
$result = mysql_query($selectQuery)
    or die('Query Failed: '.mysql_error());

// Loop through results.
$runningOK = TRUE;
$resubmitList = array();

while($row = mysql_fetch_assoc($result) and $runningOK)
{
    // Resubmit The Job
    try
    {
        $client->addTaskBackground($row['function_name'],$row['job_data']);
        $resubmitList[] = (string)$row['job_cache_id'];
    }
    catch(Exception $e)
    {
        echo "Error adding task for job id: " . $row['job_cache_id'];
        $runningOK = FALSE;
    }
}
  • 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-13T15:27:28+00:00Added an answer on May 13, 2026 at 3:27 pm

    It’s due to operator precedence. See the manual for details… here’s the relevant part.

    // "&&" has a greater precedence than
    "and"

    // The result of the expression (true && false) is assigned to $g
    // Acts like: ($g = (true && false))

    $g = true && false;

    // The constant true is assigned to $h and then false is ignored
    // Acts like: (($h = true) and false)

    $h = true and false;

    var_dump($g, $h);

    bool(false)
    bool(true)

    So, with the &&, the result of the expression is assigned to true, which evaluates to 1. With and, it evaluates to the result of the mysql function – more what you want, I reckon.

    By the way, you could also use break to eliminate the need for the $runningOK variable. To do so, remove and $runningOK from the while condition and change $runningOK = FALSE; to break; and it will end the loop if the catch block is triggered.

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

Sidebar

Related Questions

Riddle me this: I have a JTabbedPane that has custom JPanels in it. When
Riddle me this: I am using a NSURLConnection on an iPhone Simulator SDK 3.1.2
This question is about the behavior of an object with methods added to its
We had a View Model that looked like this: public class myViewModel { public
Here's a riddle for you. You have a polygon composed of exactly 4 vertices,
The postage stamp problem is a mathematical riddle that asks what is the smallest
I haven't really done much on this side of project development so please forgive
Is it possible to do the following layout with CSS but not using absolute/relative
Suppose you use the following structure: var Args = new Object(); Args.Age = '10';
I am studying the css methods Google uses to create their ui. I realized

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.