TopicName | TopicUrl | MainTopicName
------------------------------
1stSubtopic | url1 | MainOne
2ndSubtopic | url2 | MainTwo
3rdSubtopic | url3 | MainOne
As result want to get 2 php arrays
one array $MainOne
(
[TopicName1] => 1stSubtopic
[TopicUrl1] => urll
)
(
[TopicName1] => 3rdSubtopic
[TopicUrl1] => url3
)
another array $MainTwo
(
[TopicName2] => 2ndSubtopic
[TopicUrl2] => url2
)
Latter access to values like $array_from_mysql[1]['TopicName1']
, $array_from_mysql[2]['TopicName2']
and so on
May write two SELECT
statements, like SELECT TopicName, TopicUrl from table WHERE MainTopicName = ?
.
But if there are many MainTopicName
, like MainOneHundred, then SELECT
would not good solution.
But how to do it with CASE
or in other way?
The below (may be) is not correct, but I just want to understand idea
CASE MainTopicName
WHEN MainTopicName = MainOne THEN SELECT TopicName AS TopicName1
WHEN MainTopicName = MainOne THEN SELECT TopicUrl AS TopicUrl1
WHEN MainTopicName = MainTwo THEN SELECT TopicName AS TopicName2
WHEN MainTopicName = MainTwo THEN SELECT TopicUrl AS TopicUrl2
What would be correct statement with CASE
to use instead of many SELECT
statements?