douzhi9635 2014-06-26 11:25
浏览 26

分组数据基于另一个表中的父级

I am facing a tough condition, and i know that its realy going to be a tough one, but I am in no condition to solve it.

I want to show u all some db structure first

Table td_service

|-------------|---------------|---------------|
| service_id  | service_title |   pump        |
|---------------------------------------------|
|   1         |  Marine       |     1,2       | 
|---------------------------------------------|
|   2         |  gas & Oil    |     1,3       | 
|---------------------------------------------|


Now table td_product

|-------------|---------------|---------------|
| product_id  | product_title |   category_id |
|---------------------------------------------|
|   1         |  DB PUMP      |     1         |
|---------------------------------------------|
|   2         |  CG PUMP      |     2         |
|---------------------------------------------|
|   3         |  DH PUMP      |     2         |
|---------------------------------------------|



and at last, the td_category table

|-------------|---------------|
| category_id | category_title|
|-----------------------------|
|   1         |  Industry P   |
|-----------------------------|
|   2         |  Water Supply |
|-----------------------------|
|   3         |  Extraction   |
|-----------------------------|

Now the column pump in the table td_service is a string which contains the id of the pumps separated by a comma.

Now from each service I can get the list of the pumps and display them like this

$pump_list = $this->autoload_model->get_data_from_table("td_service","*","service_id = '$id'")->result_array();

$pump_list[0]['pump'] will have value 1,2


to list the pumps i can try explode operatipon on $pump_list[0]['pump']

$p_list = array();
$p_list = explode(",",$pump_list[0]['pump']);
foreach($p_list as $p)
   {
     $pump_info = $this->autoload_model->get_data_from_table("td_product","*","product_id = '$p'")->result_array();
     echo $pump_info[0]['product_title'];
    }

Now i want to show the pump names in this fashion

Industry P
-----------------------
DB PUMP, CG PUMP

when i search for a particular service id..

I cant just display the data in this grouping manner..

And one more thing, i have been strictly asked not to change the db structure.. Like some may suggest of making another table showing the relation between service and pump, but i cant do that as i have been restricted.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
    • ¥15 unity连接Sqlserver
    • ¥15 图中这种约束条件lingo该怎么表示出来
    • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
    • ¥15 流式socket文件传输答疑
    • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
    • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
    • ¥15 win10,这种情况怎么办
    • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
    • ¥100 在连接内网VPN时,如何同时保持互联网连接