我从名为view_id
的mysql表中获取最后5 history
。使用此view_id
我将从family_name
和company_name
表中获取contact_details
,company
。
现在我想将family_name
显示为升序,但不知何故它没有将family_name
显示为升序!
这是我的代码:
$getViewID = mysqli_query($link, "SELECT view_id, hid, is_save FROM history WHERE user_id = '$user_id' AND mark_as = 1 GROUP BY view_id LIMIT 5 ");
if( mysqli_num_rows($getViewID) ) {
while( $fetchViewId = mysqli_fetch_array($getViewID) ) {
$viewid = (int) $fetchViewId['view_id'];
$hid = (int) $fetchViewId['hid'];
$is_save = (int) $fetchViewId['is_save'];
$getDetails = mysqli_query($link, "SELECT cd.cdid, cd.family_name, company.company_name FROM contact_details AS cd LEFT JOIN company ON company.cid = cd.cid WHERE cd.cdid = '$viewid' ORDER BY cd.family_name ASC ");
if(mysqli_num_rows($getDetails) > 0 ) {
while($resDetail = mysqli_fetch_array($getDetails)) {
$cdid = (int) $resDetail['cdid'];
$family_name = stripcslashes($resDetail['family_name']);
$family_name = str_replace("&", "&", $family_name);
$company = stripcslashes($resDetail['company_name']);
if (strlen($family_name) >= 10) {
$family_name = substr($family_name, 0, 8);
}
if(strlen($company) >= 15) {
$company = substr($company, 0, 14);
}
$url_link = "{$url}index.php?redcdid=$cdid";
if($is_save == 1) {
$checked = 'checked = "checked"';
} else {
$checked = '';
}
echo "<li><a href='$url_link'> $family_name - $company </a> <input $checked type='checkbox' name='save_history' class='data_save' data-saveid='$viewid' data-hid='$hid'></li>";
}
} // contact end here
}
echo "<hr/>";
}