Answer the question
In order to leave comments, you need to log in
How to merge duplicate value of variables?
There is a query that displays the assigned tasks of each department. The bottom line is that now each task is displayed as in a separate department. (Result screen 1). Need help in changing the request to the view (screen 2).
Tried changing the query to
$tablev = mysql_query ("SELECT *
FROM tasks
INNER JOIN department ON tasks.id_dep_tas=department.id_dep GROUP BY department.titli_dep AND id_oper_tas=$id_oper",$db);
As a result, the output of tasks was only one per department (result screen 3)$tablev = mysql_query ("SELECT *
FROM tasks
INNER JOIN department ON tasks.id_dep_tas=department.id_dep AND id_oper_tas=$id_oper ",$db);
if(!$tablev)
{echo "Оперативок в базе нет"; }
else
{
if(mysql_num_rows($tablev) > 0)
{
echo "";
$b = 0;
while ($logic = mysql_fetch_array($tablev))
{
$b++;
echo "
<tr>
<td class='headline' colspan='8'>{$logic['titli_dep']}</td>
</tr>
<tr>
<td align='center'>$b</td>
<td>{$logic['name_tas']}</td>
<td>{$logic['data_zad_tas']}</td>
<td>{$logic['data_exe_tas']}</td>
<td>{$logic['doer_tas']}</td>
<td>{$logic['rubric_tas']}</td>
<td><input type='checkbox' checked='checked'>{data}</td>
<td><button>Ред.</button></td>
</tr>
";
}
}
}
Answer the question
In order to leave comments, you need to log in
There will be no answer here, but there will be a little advice. Hit yourself with a ruler for direct queries to the database and understand a little about stored procedures. And at the same time, instead of an asterisk, get used to writing the entire set of columns. When Joining different entities, there is a risk of gluing different tables with the same fields but different values. It is also possible that you will drag data from the database that you do not need, which will lead to unnecessary load on the database.
your trial is not counted: group by comes before part of the condition from where. For happiness, move to the end: SELECT department.titli_dep
FROM tasks
INNER JOIN department ON tasks.id_dep_tas=department.id_dep AND id_oper_tas=$id_oper GROUP BY
department.titli_dep processing. So "*" in the request does not pull.
PS: for the task at hand, you can put such a grouping into a view (projection) and then join a query to it with other tables to display the necessary data. Or puzzle with nested queries. The solution is not the only one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question