我還是很新的PHP & MySql,我不確定這是否會被視爲SQL或PHP。MySQL查詢和數組輸出從同一個數據庫列
我有以下查詢:
SELECT wp_posts.ID,
wp_postmeta.meta_value
FROM wp_posts
INNER JOIN wp_postmeta
ON wp_posts.ID = wp_postmeta.post_id
WHERE wp_posts.post_type = 'cooney_properties'
AND wp_posts.post_status = 'publish'
AND (wp_postmeta.meta_key = 'longitude' OR wp_postmeta.meta_key = 'latitude')
這是從我的WordPress的數據庫,你可以看到的經度和緯度值正在同列「meta_key」。
從上述查詢數組給了我相似的結果如下(不準確只是粗略的例子):
Array
(
[0] => stdClass Object
(
[ID] => 25016273
[meta_value] => 51.01454
)
[1] => stdClass Object
(
[ID] => 24617570
[meta_value] => 51.01447
)
[2] => stdClass Object
(
[ID] => 24780750
[meta_value] => 51.01535
)
------------------- (later on items with same ID) -------------
[141] => stdClass Object
(
[ID] => 24617570
[meta_value] => -3.107139
)
[142] => stdClass Object
(
[ID] => 24780750
[meta_value] => -3.096807
)
[143] => stdClass Object
(
[ID] => 24764956
[meta_value] => -3.104187
)
)
從數據庫的同一列作爲我不知道,如果它可以修復我的查詢還是它的一個PHP修復,我需要或者有相同ID的項目是相同的數組,並可能鍵的重新命名,如果可能的話象下面這樣:
Array
(
[0] => stdClass Object
(
[ID] => 25016273
[longitude] => 51.01454
[latitude] => -3.107139
)
[1] => stdClass Object
(
[ID] => 24617570
[longitude] => 51.01447
[latitude] => -3.096807
)
[2] => stdClass Object
(
[ID] => 24780750
[longitude] => 51.01535
[latitude] => -3.104187
)
)