how to limit to main task to be not to display in remaining loop?
<p>i have this query and code</p>

<pre><code>if(isset($_REQUEST['main_task']) &amp;&amp; ($_REQUEST['main_task'] !='')) {
    $query_task  = "SELECT * from manage_project_task where  prj_task_name LIKE  '%".$_REQUEST['main_task']."%' and prj_task_parent_id='0'";//Sort Main Task
} else {
    $query_task  = "SELECT * from manage_project_task where prj_task_project_id=$project_id  and prj_task_parent_id='0'";//Sort Main Task
}

$SelectQuery = $query_task." LIMIT ".$start.",".$limit."";      
$result_task =  $db-&gt;GetALL($SelectQuery);  
$cnt_task=count($result_task);
if ($db-&gt;Affected_Rows($result_task)&gt;0)         
{   
    for ($i=0;$i&lt;$cnt_task;$i++) { 
        $actual_hours_worked=0;         
        $actual_hours_worked2=0;

        // subtask hyperlink
        if (isset($_REQUEST['sub_task']) &amp;&amp; ($_REQUEST['sub_task'] !='')) {
            $query_subtask1  = "SELECT * from manage_project_task where prj_task_parent_id='".$result_task[$i]['prj_task_id']."' AND prj_task_name LIKE '%".$_REQUEST['sub_task']."%'";
        } else {
            $query_subtask1  = "SELECT * from manage_project_task where prj_task_parent_id='".$result_task[$i]['prj_task_id']."'";
        }
        $result_subtask1 =  $db-&gt;GetALL($query_subtask1);
        $cnt_subtask1=count($result_subtask1);
    }
}
</code></pre>

<p>this gives me main tasks and sub task in serial pattern .Now I have taken 2 textfield 1 for main task and 2nd for sub task now if i only entered subtsk in 2nd textfield then it searches the subtask with its main task but along with it also give in result the remaining main task like this</p>

<ul>
<li>main task</li>
<li>sub task (matching string in 2nd field)</li>
<li>main task</li>
<li>main task</li>
<li>main task</li>
<li>main task</li>
</ul>

<p>I think its because the second loop depends on first one.So my question is hw can get only matching subtask with its main task and not the remaining main tasks??
Please sugest any solution.</p>
