我有下面的select语句,它应该返回按姓氏排序的记录集,而不是。我已经检查了姓氏字段中是否有空白字符/空格,因为它们都是使用$last_name=trim(filter_input(input_post,'lastname',filter_sanitize_string))修剪的;。
$query_PaidOrders = "SELECT * FROM `orders` WHERE `payment_received` = '1'";
$rs_PaidOrders=$conn->query($query_PaidOrders);
if($rs_PaidOrders === false){
trigger_error('SQL error:'.$query_PaidOrders.' Error: '.$conn->error, E_USER_ERROR);
}
else{
while ($row_PaidOrders=$rs_PaidOrders->fetch_assoc()) {
$PaidOrderId=$row_PaidOrders['order_id'];
$query_select_events = "SELECT customers.last_name AS LASTNAME,
customers.first_name AS FIRSTNAME,
order_details.member_id AS MEMBERID,
order_details.event_type AS EVENTTYPE,
order_details.event_distance AS EVENTDISTANCE,
order_details.keep_stats AS KEEPSTATS
FROM `order_details`
LEFT OUTER JOIN customers ON order_details.member_id = customers.customer_id
WHERE order_details.event_id = '$eid' AND order_details.counted_for_discount='1' AND order_details.ORDERNUM = '$PaidOrderId' ORDER BY LASTNAME ASC";
$rs_events=$conn->query($query_select_events);
if($rs_events === false){
trigger_error('SQL error:'.$query_select_events.' Error: '.$conn->error, E_USER_ERROR);
}
else{
while($row_order_details=$rs_events->fetch_assoc()){
$NAME = $row_order_details['LASTNAME'].", ".$row_order_details['FIRSTNAME'];
$member_id=$row_order_details['MEMBERID'];
$event_type=$row_order_details['EVENTTYPE'];
$event_distance=$row_order_details['EVENTDISTANCE'];
$keep_stats=$row_order_details['KEEPSTATS'];
?>
<tr>
<td><?php echo "$NAME";?></td>
etc...
我的结果是:b…,h…,h…,s…,b…,r。。。。
我真的被这个难住了。任何帮助都将不胜感激。
1条答案
按热度按时间oewdyzsn1#
问题是我没有将所有内容都组合到一个查询中。一旦我这么做了,按姓氏排序就正常了。