douchilian1009 2014-06-15 07:36
浏览 22
已采纳

如何用逗号将不同的行值放在td中

I am have MySQL query table

customer_id  name    service
1              a        sms
2              b       inbox
1              a       2-way

here the customer_id 1 have two data ,when i write the query to retrieve the data from database and display it in table it only taking the first value for example customer_id 1 having sms and inbox it only displaying inbox not displaying sms ,but i want to display the both like this (sms,2-way),can any one gude how to do it.

my code:

<?php

                    $sql_selectcustomer = "SELECT customer_id,name FROM `customer` where reseller_id=1 ";

                    $result1 = mysql_query($sql_selectcustomer);

while($rows=mysql_fetch_assoc($result1))
{



    $customer_id=$rows['customer_id'];
    $customer_name=$rows['name'];

    $sql_service = "SELECT product FROM `products`  where customer_id='$customer_id'";
    //print $sql_service;
    $result_service = mysql_query($sql_service);
    while($row1=mysql_fetch_assoc($result_service))
{

    $product = $row1['product'];
    //print $product;
}

 echo '<tr>';

   echo ' <td class="edit name '.$rows["customer_id"].'">'.$customer_name.'</td>
            <td class="edit product '.$rows["customer_id"].'">'.$product.'</td>  


        </tr>';


}


?>
  • 写回答

1条回答 默认 最新

  • doucezhu3570 2014-06-15 07:38
    关注

    Use GROUP_CONCAT:

    SELECT customer_id,GROUP_CONCAT(service) as service 
    FROM `products`  
    WHERE customer_id='$customer_id' 
    GROUP BY customerid
    

    Sample result:

    customer_id     service
    -------------------------
    1               sms,2-way
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数