Good day. I need to display goods on my site, but the problem is that all the information is scattered in different database tables. If I could link most of the information by product ID, then some kind of trouble with the links. The site is on DRUPAL 6. There is a certain table url_alias, it has the following columns: pid, src, dst, language I need to pull out the address according to this condition - entries that have src = / node / 740, where 740 is a product ID. I have an array of product IDs

$pages_id= = array(840, 1411, 1390, 736, 898, 1578, 1337, 1381, 1581, 1563); 

At the moment I have such a request:

 $nodes = db_query("SELECT n.title, p.field_prod_price_value, p.field_sred_ocen_value, p.field_kol_gol_value FROM {node} n INNER JOIN {content_type_prod} p ON n.nid = p.nid WHERE n.nid IN (" . implode(",", $pages_id) . ")"); 

I need to add a sample of the dst field to the src = /node/ IN (" . implode(",", $pages_id) . ") field src = /node/ IN (" . implode(",", $pages_id) . ") I don’t understand how to do this ...

UPD:

Here is the query displays as needed

 $nodes = db_query("SELECT n.title, p.field_prod_price_value, p.field_sred_ocen_value, p.field_kol_gol_value, h.dst FROM ({node} n INNER JOIN {content_type_prod} p ON n.nid = p.nid) INNER JOIN {url_alias} h ON h.src='node/840' WHERE n.nid IN (" . implode(",", $pages_id) . ")"); 

How instead of h.src='node/840' to bust an array of $pages_id ? Or rather, instead of 840, in order to add an array traversal?

  • How does the url_alias table communicate with the rest? - Sergey
  • Curve request. You need to either remake this part ON h.src = 'node / 840', or loop through your $ pages_id array and send as many requests as there are elements in the array (a crutch). - Oboroten

1 answer 1

I need to pull out the address according to this condition - entries that have src = / node / 740, where 740 is the product ID. I have an array of product IDs

Well, as a temporary (and obviously bad, for fullscan) solution, you can offer such a trick:

 WHERE /* или ON */ REPLACE(t1.src, '/node/', '') IN ( . implode(",", $pages_id) . ) 

It would be better if you do the opposite, and add the path to the IDs:

 WHERE /* или ON */ t1.src IN ( . "/node/" . implode(",/node/", $pages_id) . )