1

我在 PHP 程序中有一个选择查询。

SELECT u.name AS name,
    u.email AS email,
    u.status AS status ,
    u.is_blocked AS is_blocked,         
    pm.plan_name AS plan_name,
    upt.amount AS amount,
    upt.payment_status AS payment_status,
    DATE_FORMAT(upt.dt, '%m-%d-%Y')AS payment_date,
    DATE_FORMAT(upt.plan_expiry_date,'%m-%d-%Y') AS exp_dt
FROM users u, user_plan_transaction upt, plan_master pm
WHERE
    u.user_id = upt.user_id
    AND upt.payment_status  IN ('PAID', 'ADMIN_PAID')
    AND upt.dt = (SELECT dt FROM user_plan_transaction WHERE user_id = u.user_id
                  ORDER BY dt DESC
                  LIMIT 1 )
    AND upt.plan_id = pm.plan_id

从这个查询中,我需要提取两个数据集:(
两个数据集都是列名,如下所示:)

(1) u.name, u.email, u.status, u.is_blocked, pm.plan_name, upt.amount, upt.payment_status, 
DATE_FORMAT(upt.dt, '%m-%d-%Y'),  DATE_FORMAT(upt.plan_expiry_date,'%m-%d-%Y')
(2) name, email, status, is_blocked, plan_name, amount, payment_status, payment_date, exp_dt

mysqli_fetch_field()我试着用函数来做。但是该函数不返回值DATE_FORMAT(upt.dt, '%m-%d-%Y')并且DATE_FORMAT(upt.plan_expiry_date,'%m-%d-%Y')在数据集中

此外,如果查询稍后更改,我希望能够再次提取字段。

例如。查询 2:

SELECT name,
       email,
       status,
       is_blocked
FROM users

然后我需要两个数据集:

(1) name, email, status, is_blocked
(2) name, email, status, is_blocked

我需要为任何 mysql 查询提取这两个数据集。

任何人都可以帮忙吗?

谢谢

我找不到基于 mysql php 的解决方案。我必须使用正则表达式来解决这个问题吗?我如何用不在括号中的逗号进行 preg_split。例如:

DATE_FORMAT(upt.dt, '%m-%d-%Y')AS payment_date,

我不想在“upt.dt”之后用逗号分隔,但在“payment_date”之后用逗号分隔。

4

0 回答 0