i am getting only one result during search,
<p>I have many records with same expertise and whenever i search then it gives only one result While the values of <code>$exp</code> is array .
suppose $exp=array(); 
I have tried my code is given below i used <code>foreach()</code></p>

 
      
        
      
      
        
      
       Submit
    

<pre><code>&lt;?php if(isset($_POST['submit'])){

echo $exp=$_POST['expertise'];
$sq=mysql_fetch_assoc(mysql_query("select distinct(requirement_id) from requirement where label_value='$exp'"));

foreach($sq as $ii){
echo $query1 = "SELECT u.`users_id`, u.`name`, u.`email`, u.`phone`, re.`label_name`, re.`label_value`, re.`requirement_id`, re.`date` FROM users u INNER JOIN requirement re ON u.`users_id`=re.`users_id` WHERE  re.`requirement_id`='$ii'";

$query=mysql_query($query1);

$resultArr = array(); //to store query result
while($row=mysql_fetch_assoc($query))
{
    $resultArr[] = $row;
} 
//print_r($resultArr);
?&gt;
&lt;table class="table table-hover"&gt;
&lt;tbody&gt;
&lt;?php
$tempUserID = "";
$tempEmail = "";
$tempPhone = "";
$tempReqID = 0; 
for($i=0;$i&lt;count($resultArr);$i++)
{
    //if user id is blank, assign temporary values we need only for one time.
    if($tempUserID=="")
    {
        $tempUserID = $resultArr[$i]['users_id'];
        $tempEmail = $resultArr[$i]['email'];
        $tempPhone = $resultArr[$i]['phone'];
         $tempReqID = $resultArr[$i]['requirement_id'];
        //printing first row
        ?&gt;
        &lt;tr&gt;
        &lt;td&gt;
            &lt;div class="row" style="background: #00ACFF; "&gt;
                &lt;p style="padding: 10px;margin: 0;color: white;"&gt;
                    &lt;i class="fa fa-user"&gt;&lt;/i&gt;
                    &lt;strong&gt; &lt;?=$resultArr[$i]['name']?&gt; &lt;/strong&gt;
                    &lt;span style="font-size:85%;"&gt;&lt;?=$resultArr[$i]['users_id']?&gt;000&lt;?=$tempReqID?&gt;&lt;/span&gt;
                    &lt;span class="pull-right"&gt;
                        &lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; &lt;?=$resultArr[$i]['date']?&gt;
                    &lt;/span&gt;
                &lt;/p&gt;
            &lt;/div&gt;
            &lt;div class="row" style="background: #EDFEAF; min-height:80px;"&gt;
                *Looking For&lt;br&gt;-&gt;
        &lt;?php
} 
    //ok
    if($tempUserID == $resultArr[$i]['users_id'] &amp;&amp;  $tempReqID==$resultArr[$i]['requirement_id'])
    {
        //printing label_name and label_value if users_id is equal to the tempuserid
        ?&gt;

                &lt;br&gt;
                 &lt;?=$resultArr[$i]['label_name']?&gt;: &lt;?=$resultArr[$i]['label_value']?&gt;
                &lt;br&gt;

        &lt;?php
    } 
    else
    {
        //if users_id is not equal to the previous one, we will close the first row(i.e.&lt;tr&gt;) and start a new one
        ?&gt;
        &lt;/div&gt;
        &lt;div class="row" style="background: #00ACFF; "&gt;
                &lt;p style="padding: 10px;margin: 0;color: white;"&gt;

                    &lt;i class="fa fa-envelope"&gt;&lt;/i&gt;&amp;nbsp;&lt;?php echo $email =  substr_replace($tempEmail,"xxxxxxxxxx",3,10);?&gt;
                    &lt;!--&lt;i class="fa fa-envelope"&gt;&lt;/i&gt; &lt;?php //$tempEmail?&gt;--&gt;
                    &lt;i class="fa fa-mobile" style="margin-left:20px"&gt;&lt;/i&gt;
                    &lt;strong&gt;&lt;?php echo $var1 =substr_replace($tempPhone, str_repeat("X", 6), 2, 6);?&gt; &lt;/strong&gt;

                  &lt;span class="pull-right"&gt;
                  &lt;a class="btn btn-default btn-xs" href="#"&gt;
                      View @&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;i class="fa fa-circle-thin"&gt;&lt;/i&gt; 12pt
                  &lt;/a&gt;
                  &lt;/span&gt;
                &lt;/p&gt;
            &lt;/div&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
        &lt;?php
        //since the users_id is not equal to the previous row, which means that data about new user is available, we will assign new values to temporary variables and start a new table row.
        $tempUserID = $resultArr[$i]['users_id'];
        $tempEmail = $resultArr[$i]['email'];
        $tempPhone = $resultArr[$i]['phone'];
        $tempReqID = $resultArr[$i]['requirement_id'];
        ?&gt;
        &lt;tr&gt;
        &lt;td&gt;
            &lt;div class="row" style="background: #00ACFF; "&gt;
                &lt;p style="padding: 10px;margin: 0;color: white;"&gt;
                    &lt;i class="fa fa-user"&gt;&lt;/i&gt;
                    &lt;strong&gt; &lt;?=$resultArr[$i]['name']?&gt; &lt;/strong&gt;
                    &lt;span style="font-size:85%;"&gt;&lt;?=$resultArr[$i]['users_id']?&gt;000&lt;?=$tempReqID?&gt;&lt;/span&gt;
                    &lt;span class="pull-right"&gt;
                        &lt;i class="fa fa-clock-o"&gt;&lt;/i&gt; &lt;?=$resultArr[$i]['date']?&gt;
                    &lt;/span&gt;
                &lt;/p&gt;
            &lt;/div&gt;
           &lt;!--the edited part --&gt;
             &lt;div class="row" style="background: #EDFEAF; min-height:80px;"&gt;
                *Looking For&lt;br&gt;-&gt;
                 &lt;br&gt;
                 &lt;?=$resultArr[$i]['label_name']?&gt;: &lt;?=$resultArr[$i]['label_value']?&gt;
                &lt;br&gt;
        &lt;?php
    }
} 
?&gt;
&lt;!--we will close the table row if current row is the last one in the result--&gt;
&lt;div class="row" style="background: #00ACFF; "&gt;
                &lt;p style="padding: 10px;margin: 0;color: white;"&gt;

                    &lt;i class="fa fa-envelope"&gt;&lt;/i&gt; &lt;?php echo $email =  substr_replace($tempEmail,"xxxxxxxxxx",3,10);?&gt;
                    &lt;i class="fa fa-mobile" style="margin-left:20px"&gt;&lt;/i&gt;
                    &lt;strong&gt; &lt;?php echo $var1 =substr_replace($tempPhone, str_repeat("X", 6), 2, 6); ?&gt;&lt;/strong&gt;

                  &lt;span class="pull-right"&gt;
                  &lt;a class="btn btn-default btn-xs" href="#"&gt;
                      View @&amp;nbsp;&amp;nbsp;&amp;nbsp;
                      &lt;i class="fa fa-circle-thin"&gt;&lt;/i&gt; 12pt
                  &lt;/a&gt;
                  &lt;/span&gt;
                &lt;/p&gt;
            &lt;/div&gt;
        &lt;/td&gt;
    &lt;/tr&gt;





        &lt;/div&gt;&lt;!--/col-9--&gt;
        &lt;/tbody&gt;
&lt;/table&gt;    

&lt;?php } } ?&gt;
</code></pre>