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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:58:41+00:00 2026-05-28T18:58:41+00:00

I am pulling information that has cities attached to it and i would like

  • 0

I am pulling information that has cities attached to it and i would like the information to be in a order where it shows the current city first, then cities in an order by distance from the city searched. I have the cities in the order that i would want them shown in an array called $nearby_city_array. Is there any way that I could pull the data, in order, according to where it shows up in my array?

$query = "SELECT
             username, city, state
        FROM
        ...
        WHERE
                      city = '" . $city . "'
              state = '" . $state . "'
            ORDER BY " . $nearby_city_array . ";
    $result = mysql_query($query, $db) or die(mysql_error($db));

Any ideas would be great thanks.

  • 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-28T18:58:42+00:00Added an answer on May 28, 2026 at 6:58 pm

    While you have found a better solution, i.e. one using the information stored in the database, someone else visiting this question might search for a solution for the original question.

    This is the idea:

    CREATE TEMPORARY TABLE tmp_order (cntup INTEGER AUTO_INCREMENT, city VARCHAR(100))
    INSERT INTO tmp_order (city) VALUES ('a'), ('b'), ... -- this is the order
    SELECT <fields> FROM mytable JOIN tmp_order USING (city) ORDER BY cntup
    

    This creates a temporary table containing the data in the order as they are in the list. If you join this table to your original query and order the result by the row ID in the temp table, you get exactly what you want.

    As said, if you can omit this list and use data which are already present in the DB, it is better.

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

Sidebar

Related Questions

This is something that has been pulling at me for a while. Consider a
I'm pulling dates from an xml feed that has this form 12/10/2010 19:30:00 and
I'm pulling in data from an external place database that returns JSON of information
I've got an app that displays information from our web service. The user has
I'm working on an app that will both record an audio file, and then
I am working on a database that has an existing Individuals table that every
I have a server at http://foobar that returns a JSON object containing information about
I have a database with a row that has TEXTTEXT inside a noteText column
I believe that this question has been asked in a few different forms, but
I know, that I am not the first one to try to use Cocoa

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.