0

I have done with fetching and display the data. But the problem is ,its display the data of fetched row in the same row of html table. For example : i want to display like this

                  ID | Name | Desination
                   ......................
                   1 | ABC | Developer
                   2 | PQR | Tester
                   3 | XYZ | Developer

But its showing as -

                   ID | Name | Desination
                   ......................
                    1 | ABC | Developer   2 | PQR | Tester   3 | XYZ | Developer

I have done something like this-

$sql = " SELECT candidate.cand_number,candidate.cand_fname,candidate.cand_desc FROM candidate ".$join.' where '.$condition;
$result = mysql_query($sql) or die(mysql_error()); 

Correct me with the display format of table.

 <div class="box-body table-responsive no-padding">
     <table class="table table-hover">
          <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Designation</th>
          </tr>
          <tr>
              <?php

                   If(mysql_num_rows($result)>0)
                   {
                     while($row=mysql_fetch_array($result))
                     {  

                ?>
                  <td><?php echo $row['cand_number']; ?></td> 
                  <td><?php echo $row['cand_fname']; ?></td> 
                  <td><?php echo $row['cand_desc']; ?></td> 
                <?php

                }
                }
                 ?>

              </tr>
       </table>
    </div>

4 Answers 4

5

You need to repeat row not column

 <?php
If (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_array($result)) {
        ?>
        <tr>
            <td><?php echo $row['cand_number']; ?></td> 
            <td><?php echo $row['cand_fname']; ?></td> 
            <td><?php echo $row['cand_desc']; ?></td> 
        </tr>
        <?php
    }
}
?>
Sign up to request clarification or add additional context in comments.

7 Comments

@AbhiAhere..Thank you...it worked. How would i make the "name" as hyperlink and after on click of the link it should display the whole details of that candidate.
you are welcome . If you find the the answer helpful then check it as correct – abhi
As i have mentioned above You need to repeat row not column, all the explanation is in the line itself
@NarendraSisodia..ok the link too worked..but give some idea how would i display that particular candidate details when the link is clicked. i.e. it should execute another sql query on click. to display his whole details
...how would i display that particular candidate details when the link is clicked. i.e. it should execute another sql query on click. to display his whole details
|
0

Use this HTML and try

<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
   <th>ID</th>
   <th>Name</th>
   <th>Designation</th>
</tr>

          <?php

               If(mysql_num_rows($result)>0)
               {
                 while($row=mysql_fetch_array($result))
                 {  

            ?>
             <tr>
              <td><?php echo $row['cand_number']; ?></td> 
              <td><?php echo $row['cand_fname']; ?></td> 
              <td><?php echo $row['cand_desc']; ?></td> 
            </tr>
            <?php

            }
            }
             ?>


   </table>
</div>

Comments

0

You need to add into the while loop. Because of this your all data is printed inside first row.

<?php
If (mysql_num_rows($result) > 0) {
    while ($row = mysql_fetch_array($result)) {
        ?>
        <tr>
            <td><?php echo $row['cand_number']; ?></td> 
            <td><?php echo $row['cand_fname']; ?></td> 
            <td><?php echo $row['cand_desc']; ?></td> 
        </tr>
        <?php
    }
}
?>

6 Comments

@CodeLord..Thank You..it worked for me. :) How would i make the "name" as hyperlink and after on click of the link it should display the whole details of that candidate.
@vinod just add anchore tag for name like <a href="#"><?php echo $row['cand_fname']; ?></a>
how would i display that particular candidate details when the link is clicked. i.e. it should execute another sql query on click. to display his whole details
You need to create another page for this send your candidate id in url parameter. This is broad question . You need to post this question so I can give brief answer.
@CodeLord..wait I brief you with my code and send you the link. soon. Thank you
|
0

In addition to the other answers: don't forget to sanitise $join and $condition. This to prevent SQL injection.

1 Comment

Thank you! its just a raw code. we will implement it for sure!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.