我有以下mysqli查询,该查询根据projects_log
显示来自$cdid
表的所有数据
$getlog = mysqli_query($link, "
SELECT projects_log.*, users.username
FROM projects_log
LEFT JOIN users ON users.user_id = projects_log.user_id
WHERE projects_log.cdid = '$cdid'
ORDER BY projects_log.pl_id DESC ");
此查询显示while循环中的以下数据
Project Name
=============
Mr. Bean
Mr. Benn
New Company3
New company project
Mobile
A T ETC
Mr. Bean
A Ten
现在从这个while循环结果,我首先显示最新的3个项目名称并隐藏所有剩余的“项目名称”。这个隐藏“项目名称”可以使用(+)按钮显示。像循环中显示/隐藏的东西:
$count = 4;
while ($fetclog = mysqli_fetch_array($getlog)) {
$log_p_id = (int) $fetclog['p_id'];
$log_username = inputvalid($fetclog['username']);
$log_status = inputvalid($fetclog['status']);
$new_log_status = inputvalid($fetclog['status']);
$log_date = inputvalid($fetclog['date_time']);
$expand = explode(':', $log_date);
$log_date = $expand[0] . $expand[1];
$getproject_name = mysqli_query($link, "SELECT projects.p_name, company.* FROM projects LEFT JOIN company ON projects.cid = company.cid WHERE p_id = '$log_p_id' ");
$log_result = mysqli_fetch_array($getproject_name);
$log_projectName = $log_result['p_name'];
$log_company = $log_result['company_name'];
$get_name = mysqli_query($link, "SELECT status_name FROM status WHERE sid = '$new_log_status' ");
$get_result = mysqli_fetch_array($get_name);
$new_log_status = $get_result['status_name'];
if (empty($new_log_status)) {
$new_log_status = "Long List";
} else {
$new_log_status = $new_log_status;
}
// if logged in user is a owner of this project or having any assign project...
$logged_user_id = $_SESSION['user_id'];
$project_check = mysqli_query($link, "SELECT p_id FROM projects WHERE p_owner_id = '$logged_user_id' ");
$project_check_2 = mysqli_query($link, "SELECT p_id FROM projects_assign_users WHERE assign_user_id = '$logged_user_id' ");
$exit_p_id = array();
while ($project_check_fetch = mysqli_fetch_array($project_check)) {
$exit_p_id[] = $project_check_fetch['p_id'];
}
$exit_p_id_2 = array();
while ($project_check_fetch_2 = mysqli_fetch_array($project_check_2)) {
$exit_p_id_2[] = $project_check_fetch_2['p_id'];
}
if ($count > $count_num) {
echo "<tr class='collapse_project_log'>";
if (in_array($log_p_id, $exit_p_id) || in_array($log_p_id, $exit_p_id_2)) {
echo "<td valign='top'><a class='project' onclick='getProjectForm($log_p_id)'>$log_projectName</a></td>";
} else {
echo "<td valign='top'>$log_projectName</td>";
}
// if logged in user is a owner of this project or having any assign project...d
echo "<td valign='top'>$log_company</td>";
echo "<td valign='top'>$log_username</td>";
echo "<td valign='top'><a><label class='' for='modal-2' onclick='showpstatus($cdid, $log_p_id);'>$new_log_status</a></label></td>";
echo "<td valign='top'>$log_date</td>";
echo "</tr>";
} else {
echo "<tr>";
if (in_array($log_p_id, $exit_p_id) || in_array($log_p_id, $exit_p_id_2)) {
echo "<td valign='top'><a class='project' onclick='getProjectForm($log_p_id)'>$log_projectName</a></td>";
} else {
echo "<td valign='top'>$log_projectName</td>";
}
echo "<td valign='top'>$log_company</td>";
echo "<td valign='top'>$log_username</td>";
echo "<td valign='top'><a><label class='' for='modal-2' onclick='showpstatus($cdid, $log_p_id);'>$new_log_status</a></label></td>";
echo "<td valign='top'>$log_date</td>";
echo "</tr>";
}
$count++;
}
以上所有工作正常。
现在,在3个可见的最新项目中,它向我展示:
Project Name
============
Mr. Bean
Mr. Bean
New Company
但我希望这个前3个可见项目的名称应该是唯一的。我怎么能这样做?
类似于显示来自while循环的唯一数据结果不使用mysql查询。