如何使PHP(或其他语言)中的长句子看起来很漂亮?

时间:2016-11-01 09:05:38

标签: php mysql sql code-formatting

这是一个例子;为了看起来舒服,我填写了一些标签和换行符;我正在寻找一些更好的方法,除了使用'。'链接他们。

$str_sql = "SELECT 
          sc.`id` AS 'payment_id',
          sc.`order_id` AS 'order_id',
          od.`partner_id` AS 'partner_id',
          pt.`partner_name` AS 'partner_name',
          od.`term` AS 'order_terms',
          od.`has_pay` AS 'paid_terms',
          sc.`sort_order` AS 'current_term',
          FROM_UNIXTIME(sc.`repayment_time`) AS 'payment_time',
          FROM_UNIXTIME(sc.`receive_time`) AS 'pay_time',
          sc.`order_price` AS 'term_price',
          od.`add_time` AS 'order_time',
          sc.`status` AS 'status',
          od.`order_price` AS 'order_price',
          usr.`user_name` AS 'user_name',
          usr.`id` AS 'user_id',
          usr.`user_cell` AS 'user_cellphone',
          IF(sc.`status` IN (0,3), 1 , 0 ) AS 'overdue',

        FROM 
          mayidev.`lzh_order_payment_schedule` sc 
          JOIN lzh_order od 
            ON sc.`order_id` = od.`id` 
          JOIN lzh_partners pt 
            ON od.`partner_id` = pt.`id` 
          JOIN lzh_order_user usr 
            ON od.id = usr.order_id 
          JOIN lzh_partner_overdue_interest po 
            ON po.`partner_id` = pt.id 
        WHERE sc.`repayment_time` < 1477441800
        AND sc.`receive_time` = 0
          AND sc.`status` != 1
          AND od.`status` = 4 ;";

1 个答案:

答案 0 :(得分:1)

在PHP中使长SQL语句看起来很漂亮的最好方法是将SQL代码与PHP代码分开。最好的方法是在SQL中创建viewstored procedure来获取数据。在PHP中,您并不需要所有这些JOIN逻辑。最好存储在SQL服务器上以保持代码的可维护性。

在PHP方面,您可以SELECT * FROM viewCALL procedure()