dongxia1390 2009-09-22 07:28
浏览 10
已采纳

PHP修剪行结果?

Hello I'm getting results in format

location1 2 4
location2 3 2
location3 0 0
location1 1 0

How can I trim results so that row returning 0 and 0 is not displayed ? thank you

.................

Here is Mysql query, I don't know how to trim it from MySQL so I thought using PHP ..

    SELECT hotelas.name, hotelas.address, hotelas.city, hotelas.country, hotelas.hotel_id 
AS hotelid, 
COUNT( DISTINCT apart.apartman_id ) AS number_of_free_ap, 
COUNT( DISTINCT room.apartman_id ) AS num_of_free_rooms
    FROM hotel AS hotelas
    LEFT JOIN apartman AS apart ON ( apart.apartman_hotel = hotelas.hotel_id
    AND apart.occupied =0
    AND apart.what =1 )
    LEFT JOIN apartman AS room ON ( room.apartman_hotel = hotelas.hotel_id
    AND room.occupied =0
    AND room.what =0 )
    GROUP BY hotelas.hotel_id

TABLE field what, 0 - for room, 1 - apartment

So I get a few columns among which the most important ones are count columns , free rooms and free apartments. So I have a test hotel which is full 0 rooms and 0 apartments and I want is removed from this list where all other hotels have at least one room or one apartment available.

  • 写回答

3条回答 默认 最新

  • drl2051 2009-09-22 07:33
    关注

    if you are querying you database to get this information and you can change the query, that would be the best place for it.

    SELECT *
    FROM myTable
    WHERE
        firstColumn != 0
    OR
        secondColumn != 0
    

    If you are getting this in PHP from some other source (CSV or something), or you don't have control over the query, use array_filter():

    // i'm assuming each line in your example is an array of values
    $myArray = array_filter($myArray, 'noDoubleZeroes');
    
    function noDoubleZeroes($line) {
        return $line[1] != 0 || $line[2] != 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

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