Jump to content
php.lv forumi

MySQL array funkcijas


Salv

Recommended Posts

Sveiciens!

 

Pastāv kaut kāda funkcija, kura ļautu MySQL selectā vienu no vērtībām atgriezt kā masīvu? Teiksim zemāk redzamajā pieprasījumā iekšējais selects atgriež vairākas attribute_id vērtības, vēlos tās atgriezt kā masīvu. 

SELECT
	products.id				AS id,
	products.parent_id			AS parent_id,
	products.category_id			AS category_id,
	products.price				AS price,
	products.sale_price			AS sale_price,
	product_contents.name			AS name,
	languages.id				AS lang_id,
	languages.name				AS lang_name,
        ( SELECT attribute_id AS id
          FROM ...)                           AS attribute_id

FROM
	products
	LEFT JOIN product_contents ON
	        product_contents.product_id = products.id AND
		product_contents.language_id IN (".$language_id.")
	LEFT JOIN languages ON
		languages.id = product_contents.language_id
WHERE
	1=1

Link to comment
Share on other sites

Nu viens veids, kā to varētu izdarīt ar vienu kveriju būtu izmantot https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concatun pēc tam jau ar php (piem. explode()) sadalīt to lauku un iegūt masīvu.

 

Bet ja vien tur nav kaut kāds ļoti specifisks iemesls tā darīt, manuprāt uztaisīt vēl vienu kveriju atribūtu iegūšanai būtu loģiskāk.

Edited by mad182
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...