user3386779
user3386779

Reputation: 7215

creating in html table in php

I want to create dynamic table with mysql data I want to create table as mentioned in 'demo1' but I have problem with with table format as shown in 'demo' . query and values are correct but I want to get corret table format.

demo 1 enter image description here

demo enter image description here

  <table class=demo border=1>
    <tr style='height:10px'>
    <td style='align:center;width:30px'class="client">Clientname</td>
<td style='align:center'class="req">Requirement</td>


<td style='align:center;width:30px' class="resume">Resume</td>
<td style='align:center;width:30px' class="resume">Interview</td>
<td style='align:center;width:30px'class="status">Placed</td></tr>
  <tr>  
        <?php  
        include "config.php";
      //  echo '<table>';
       $sql="select * from client";    
        $sql1=mysql_query($sql);

        while($fet=mysql_fetch_assoc($sql1))  
        {
      //   echo '<tr>';
        $c_id=$fet['c_id'];
        $c_name=$fet['c_id'];

            echo '<td>'.$fet['c_name'].'</td>';
          echo '<td colspan=4>';
           $res="SELECT a.req_id,a.title,(select count(*) from resume as b where a.req_id=b.req_id) as submittal,(select count(b.interview) from resume as b where b.e_id='$ses' and b.interview!='0000-00-00' and a.req_id=b.req_id)as interview,(select count(*) from resume as b where placed=1 and a.req_id=b.req_id) as placed FROM `requirement` as a,resume as b  where a.c_id='$c_id' and a.e_id='$ses' group by a.req_id";
            $re=mysql_query($res);
            echo '<table border=1 >';   
            while($res1=mysql_fetch_assoc($re))
            {
            echo '<tr>';
            echo '<td>'.$res1["title"].'</td>';
            echo '<td>'.$res1["submittal"].'</td>';
            echo '<td>'.$res1["interview"].'</td>';
            echo '<td>'.$res1["placed"].'</td>';
            echo '</tr>';
            }
             echo '</table>';
             echo '</td>';
         echo '</tr>';
        }
      ?>
      </table>

Upvotes: 0

Views: 105

Answers (2)

Amir Mohsen
Amir Mohsen

Reputation: 851

you can use use this:

<table class=demo border=1>
  <tr style='height:10px'>
    <td style='align:center;width:30px'class="client">Clientname</td>
    <td style='align:center'class="req">Requirement</td>


    <td style='align:center;width:30px' class="resume">Resume</td>
    <td style='align:center;width:30px' class="resume">Interview</td>
    <td style='align:center;width:30px'class="status">Placed</td>
  </tr>
    <?php
    include "config.php";
    //  echo '<table>';
    $sql="select * from client";
    $sql1=mysql_query($sql);

    while($fet=mysql_fetch_assoc($sql1))
    {
        //first count your group rows
        $count = 5;//group rows

        //create gruop start
        $i = 1;
        while($i < $count){

            //group row start
            echo "<tr>";

            if($i = 1)
                echo "<td rowspan='$count'>your client</td>";

            echo '<td>title</td>';
            echo '<td>submittal</td>';
            echo '<td>interview</td>';
            echo '<td>placed</td>';

            //group row end
            echo "</tr>"
        }
    }
    ?>
</table>

Upvotes: 1

Mosh Feu
Mosh Feu

Reputation: 29347

Remove colspan=4 and add rowspan with the number of the rows under the specific client.

http://www.w3schools.com/tags/att_td_rowspan.asp

Upvotes: 0

Related Questions