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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:22:46+00:00 2026-05-13T23:22:46+00:00

I am using solr search engine to query an index for classifieds that match

  • 0

I am using “solr” search engine to query an index for classifieds that match a given criteria. The results are the ID:numbers of the classifieds, which I then use to find all matches in a MySql database with those ID:s.
The ID:s returned are put into an array.

As you can see below the array is imploded.
Then I use the “IN” to find all matches.

$solr_id_arr_imploded = implode("', '", $solr_id_arr);
$query = "SELECT mt.*, $sql_tbl.* FROM classified mt LEFT JOIN $sql_tbl ON 
$sql_tbl.classified_id = mt.classified_id WHERE mt.ad_id IN ('$solr_id_arr_imploded')";

$sql_tbl is the category chosen by the user, in this case lets say it is “cars”.

My problem is this:
I have the ID:numbers in an order (inside the array), but MySql doens’t “care” about this order. MySql displays the oldest item first no matter what order the array is in.

So here is one same query displayed with two different “array-directions”:

SELECT mt.*, fordon.* FROM classified mt LEFT JOIN fordon ON fordon.classified_id = mt.classified_id WHERE mt.ad_id IN ('Bmw_520i_Svensksald_784332731', 'Bmw_M3_Svensksald_755599519', 'Bmw_M3_E46_Full-utrustad_338210082')

SELECT mt.*, fordon.* FROM classified mt LEFT JOIN fordon ON fordon.classified_id = mt.classified_id WHERE mt.ad_id IN ('Bmw_M3_E46_Full-utrustad_338210082', 'Bmw_M3_Svensksald_755599519', 'Bmw_520i_Svensksald_784332731')

As you can see the ID:s are reversed in the second query above… But they are still displayed in the same order anyways. Why?

Should I use some other method of finding all MySql matches with ID:s from an array?

Ideas?

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-13T23:22:46+00:00Added an answer on May 13, 2026 at 11:22 pm

    This should do it:

    SELECT mt.*, $sql_tbl.* FROM classified mt 
    LEFT JOIN $sql_tbl  
    ON $sql_tbl.classified_id = mt.classified_id 
    WHERE mt.ad_id IN ('$solr_id_arr_imploded') 
    ORDER BY FIELD(mt.ad_id,'$solr_id_arr_imploded')
    

    See Order By Field in Sorting Rows.

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

Sidebar

Related Questions

I am using the Solr search engine. It returns my search results like so:
I am trying to setup a search engine using Solr (or Lucene) which could
I am using Tika integrated in SOLR to index documents and allow search on
I implement search engine with solr that import minimal 2 million doc per day.
We are using SOLR as our search engine. When I search for a product,
I'm using Solr for search. I have documents that have an integer field popularity
I am using solr to search through indices written through lucene's index writer. My
Currently, Im using solr as a search server. My issue is that I do
I am using ajax-solr to generate search results from Solr. Is there any way
We're using Solr to search articles of various lengths. We index both descriptive metadata

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.