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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:26:51+00:00 2026-06-11T23:26:51+00:00

I am writing a code, where I have to produce a query with many

  • 0

I am writing a code, where I have to produce a query with many OR statements, and I think there is a more comfortable way to this than:

foreach ($plz as &$value) {
    if (empty($i)) {
        $query = "WHERE plz='$value'";
    } else {
        $query = "$query OR plz='$value'";
    }
    $i++;
}
$sql = mysql_query("SELECT * FROM table $query");
while ($data = mysql_fetch_array($sql)) {
    //do something
}
  • 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-11T23:26:52+00:00Added an answer on June 11, 2026 at 11:26 pm

    If you have multiple values a column may take, just connect them using the IN operator:

    Instead of writing

    ... WHERE col=1 OR col=2 OR col=3
    

    just write

    ... WHERE col IN (1,2,3)
    

    To collect all entries in PHP, use an array and implode() later on:

    // collecting values
    $vals = array();
    $vals[] = 1;
    $vals[] = 2;
    // ...
    
    // add them to your query
    $query .= ' WHERE col IN ( ' . implode( ',', $vals ) . ')';
    
    // execute the query ...
    

    In case your values are not integer, but need to be enclosed in apostrophes within the query, insert them that way into the array in the first place:

    $vals[] = "'my string value'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing code to clone object but have no cue from Hobo documentation.
I'm writing code in C++ and have defined PI as: const double MathConstants::PI =
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I am writing code to performance test a web site. I have the following
I have a programming experience with statically typed languages. Now writing code in Python
I have been writing Python code for only a couple of weeks, so I'm
I have been writing some code to create a byte array I will be
I have a year's experience writing client code but none with server stuff. I
I'm writing a code to identify the subfix for a given number. I have
I am fairly new to writing C code and I am sure I have

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.