mysql Date返回奇怪的字符

时间:2017-08-23 20:52:12

标签: javascript php mysql

所以我有这个大的查询工作正常,直到我添加jobs.deliveryDate。查询仍然没有错误,但当我回显我的值时,它回应这些奇怪的字符。我想知道它是否与MySQL数据类型有关。这个变量的数据类型为Date,但是我能够很好地引入Datetime的数据类型。 Screen Shot of characters

$query = $connect->prepare("
    (SELECT 
    jobs.jobID,
    jobs.jobName,
    jobs.pdf,
    jobs.deliveryDate,
    jobstatus.status,

    rooms.roomID, 
    rooms.roomName, 
    rooms.assemblyS,
    rooms.assemblyF,
    rooms.assembledF,
    rooms.assemblyNeeded,
    rooms.woodType,
    rooms.finishType,
    rooms.finishColor,
    rooms.numberOfBoxes,
    rooms.isRush,
    rooms.description,

    jobnotes.note
    FROM jobs 
    LEFT JOIN rooms ON jobs.jobID = rooms.jobID 
    LEFT JOIN jobnotes ON jobnotes.jobID = jobs.jobID
    LEFT JOIN jobstatus ON jobstatus.statusOrder = jobs.statusOrder
    WHERE (rooms.assemblyNeeded = 1) AND ((rooms.isRush = 1 AND rooms.assemblyF = 0) OR (rooms.isRush = 1 AND rooms.assemblyF IS NULL))
    GROUP BY rooms.roomID)

    UNION ALL

    (SELECT 
    jobs.jobID,
    jobs.jobName,
    jobs.pdf,
    jobs.deliveryDate,
    jobstatus.status,

    rooms.roomID, 
    rooms.roomName, 
    rooms.assemblyS,
    rooms.assemblyF,
    rooms.assembledF,
    rooms.assemblyNeeded,
    rooms.woodType,
    rooms.finishType,
    rooms.finishColor,
    rooms.numberOfBoxes,
    rooms.isRush,
    rooms.description,

    jobnotes.note
    FROM jobs 
    LEFT JOIN rooms ON jobs.jobID = rooms.jobID 
    LEFT JOIN jobnotes ON jobnotes.jobID = jobs.jobID
    LEFT JOIN jobstatus ON jobstatus.statusOrder = jobs.statusOrder
    WHERE ((rooms.assemblyNeeded = 1 AND jobstatus.statusOrder >= 0 AND rooms.assemblyF IS NULL)
    OR (rooms.assemblyNeeded = 1 AND jobstatus.statusOrder >= 0 AND rooms.assemblyF = 0))
    AND ((rooms.isRush = 0 AND rooms.assemblyF = 0) OR (rooms.isRush = 0 AND rooms.assemblyF IS NULL))
    GROUP BY jobs.jobName, rooms.finishColor 
    ORDER BY jobs.statusOrder = 7 DESC, deliveryDate, jobName, finishType LIMIT 50)");
if(!$query) {
    echo("Query Failed Because " . mysqli_error($connect));
};

$query->execute();
$result = $query->get_result();


while($row = mysqli_fetch_assoc($result)) {
    $deliveryDate = $row['deliveryDate'];
    echo $deliveryDate;
}

1 个答案:

答案 0 :(得分:0)

这可能不是解决此问题的最佳方法,但我可以使用

获取日期
EXTRACT(YEAR FROM jobs.deliveryDate) as deliveryDateYear,
EXTRACT(MONTH FROM jobs.deliveryDate) as deliveryDateMonth,
EXTRACT(DAY FROM jobs.deliveryDate) as deliveryDateDay,