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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:42:20+00:00 2026-06-01T03:42:20+00:00

So basically I have website that has names of cities that can be checked

  • 0

So basically I have website that has names of cities that can be checked off. I save them into local storage under one key. And then I send them Via Ajax over to my php script below. Then in php I explode the city variable on “,” and I filter the cities depending on which ones were given. But right now I only know how to do this manually, for example city[0], city[1] etc. Is there a way I can continually put those variables into mysql statement depending on how many there are? I am sorry if I am being confusing, I’m just totally lost. Any help would be appreciated.

Here is my code:

<?php
$con = mysql_connect("localhost", "test", "test") or die('could not connect to mysql');

mysql_select_db("test", $con) or die('could not find database');


$city2 = $_POST['city2'];

$cities = explode(",", $city2);

$rep2 = $_POST['rep2'];

$status2 = $_POST['status2'];

$size2 = $_POST['size2'];

$type2 = $_POST['type2'];

$lat2 = $_POST['lat2'];

$long2 = $_POST['long2'];

$radius2 = $_POST['radius2'];

if ($city2 == '') {
    $city_stat = " city RLIKE '.*' ";
} else {
    $city_stat = " (city='$cities[0]' OR city='$cities[1]') ";

}


if ($radius2 == '') {
    $radius_stat = '10';
} else {
    $radius_stat = $_POST['radius2'];

}


if ($size2 == '') {
    $size_stat = '';
} else {
    $size_stat = " AND size='$size2' ";

}

if ($rep2 == '') {
    $rep_stat = '';
} else {
    $rep_stat = " AND rep='$rep2' ";

}


if ($status2 == '') {
    $status_stat = '';
} else {
    $status_stat = " AND status='$status2' ";

}



$result = mysql_query("SELECT lat,lng,id,rep,rep_num,name,city,state,zip,address,status,category,size FROM test WHERE $city_stat $rep_stat $size_stat $status_stat LIMIT 0 , 50 ");

while ($array = mysql_fetch_assoc($result)) {
    $array_json[] = $array;




}


echo json_encode($array_json);
?>
  • 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-01T03:42:22+00:00Added an answer on June 1, 2026 at 3:42 am

    From what I think you are asking is that there might be a variable number of cities and you want to set a conditional that the city can be any of them.

    So instead of:

    $city_stat = " (city='$cities[0]' OR city='$cities[1]') ";
    

    You can do something like this:

    $city_stat = '(city IN ('.implode(',',$cities).'))';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, we have an ASP website right now that I'm converting to PHP. We're
Basically, I have a CodeIgniter site that registers users through this url: http://website.com/user/register/1 Unfortunately,
I currently have a Rails website that has some Prototype scripting in it. My
I have a website that basically allows customers to build a cart with an
I am currently creating a website in php that has a database backend (can
I have a website that has lots of prototype.js ajax calls and now we
I have a small project that basically a Python wrapper to a websites API.
Basically I have a website. I have a properly setup sitemap so I assume
Basically my question is i have a website which was developed around 3 years
Basically I have a masterpage defining the basic layout of the website. What I

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.