Advertisement:

Author Topic: Add to search query cars and real estate attributes  (Read 1636 times)

steam

  • Newbie
  • *
  • Posts: 17
Add to search query cars and real estate attributes
« on: June 02, 2017, 10:13:15 pm »
Hi,

I want to show on the normal search list items attributes of cars and real estate for thats items.

For the performance reason I don't want to check out these extra data on loop for each item.

My idea is add before execute search query left inner join with the car and real estate tables so that it always returns normal item if there are no car or real estate records.

It's possible? Or am I wrong?

Thanks in advance

steam

  • Newbie
  • *
  • Posts: 17
Re: Add to search query cars and real estate attributes
« Reply #1 on: June 14, 2017, 10:44:10 am »
No idea?  :-[
« Last Edit: June 14, 2017, 10:47:51 am by steam »

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Add to search query cars and real estate attributes
« Reply #2 on: June 14, 2017, 11:49:43 am »
I'm not sure I fully understood you, but the performance overhead with those plugins is very tiny, do not over optimize.

steam

  • Newbie
  • *
  • Posts: 17
Re: Add to search query cars and real estate attributes
« Reply #3 on: June 16, 2017, 11:43:58 am »

First, thanks for answering my question. I will try to explain better.

In the normal search, the items are obtained from database, and then by loop displayed it on search.php.

http://anunciola.es/anuncios-segundamano-gratis


I want to show in the list, car items with their attributes like year, motor, marches, km and real state items with a year, number of rooms, number bathrooms etc. like details.

I think that for doing this right now, I have to do it in the loop of items obtained, detect if item is a car or real steate and make extra query to the database to obtain its attributes.

I thought it would be more optimal include the car and real state tables in the main search query that brings all items (normal items, cars, real state, jobs) and not in the loop when the ads are painted.


Thanks

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Add to search query cars and real estate attributes
« Reply #4 on: June 16, 2017, 12:02:16 pm »
I doubt it would be more optimal because you are adding more tables to the query and in most cases the join would be null (you add the tables for real estate, but no listing is real estate,...)

I think the "best" way to do this, is to do the search, then loop through the items (without showing them) and put in one array the ID of those that are cars, in another those that are real estate. Then, query the database for those items (one query for each, one for cars and another for real estate. Finally, show the listings with the added data of those queries. Something like

(pseudo code)
Code: [Select]
$items = .... from the search...
$cars = array();
$realestate = array();

foreach($items as $item) {
    if(item category == cars) {
        $cars[] = item id
    } else if(item category == cars) {
        $realestate[] = item id
    }
}

$carsdata = query(SELECT * FORM tbl_plugin_cars WHERE id IN ($cars));
$realestate = query(SELECT * FORM tbl_plugin_realestate WHERE id IN ($realestate));


foreach($items as $item) {

// HTML, SHOW LISTING
if (item is cars) {
// SHOW ADDITIONAL CARS DATA FROM $carsdata
}
...

}




steam

  • Newbie
  • *
  • Posts: 17
Re: Add to search query cars and real estate attributes
« Reply #5 on: June 16, 2017, 08:26:08 pm »
_CONEJO, thanks a lot for the suggestion.

The idea is good, I will see the implementation.

Regards