开发者

Trying to show the data coming from mysql using PHP and html

I am trying to show the data coming from mysql database as a table format using PHP like this

         $query = "SELECT CONCAT(usrFirstname,'',usrSurname) As FullName,usrNickname AS Nickname,";
          $query.= "usrEmail As EmailAddress,usrGender AS Gender,DATE(usrDOB) As DOB,usrBelt AS BeltId,ggName As Groupname ";
       $query.= "FROM user LEFT JOIN gyg ON user.usrIndex = gyg.usrIndex;";
       $result = mysql_query($query);
 echo mysql_error();
 if($result)
{
 $row=  mysql_fetch_array($result);
 if($row)
 {    
  $fullname = $row['FullName'];
  $nickname = $row['Nickname'];
  $emialid = $row['EmailAddress'];
  $gender  = $row['Gender'];
  $Dateofbirth = $row['DOB'];
  $belt = $row['BeltId'];
  $group = $row['Groupname'];    
 }

    } 

and the html code is like this:

<table height= "600" width="800">
    <tr style="vertical-align: top; text-align:top display:inline-block">
    <thead>   
          <td>FUll name</td><td> Nickname<?php echo $nickname ?></td><td>Email Address<?php echo $emialid ?></td><td>Gender<?php echo $gender ?></td><td>DOB <?php echo $Dateofbirth ?><td>BELT ID <?php echo $belt ?></td><td>GROUP <?php echo $group ?></td>  
      </thead> 
    </tr> 
 </table>

I want to show like this:

    fullname   nickname   emailid  gender  dob  beltid  group
      xxxxx      xxxxx     xxxxx     xxx   xxx   xxx    xxxx
      xxxxx      xxxxx     xxxxx     xxx   xxx   xxx    xxxx

but开发者_StackOverflow it was displaying like this:

          fullname xxxxx    nickname xxxxx    emailid xxxxx   gender xxxxx   dobxxxxx   beltid xxxxx   groupxxxxx 

and I have four rows coming from the database but it was displaying only one row.

How can I solve this problem? Can anyone help on this?

Modified code : it was displaying like this:

 fullname   nickname   emailid  gender  dob  beltid  group
       xxxxx      xxxxx     xxxxx     xxx   xxx   xxx    xxxx
       xxxxx      xxxxx     xxxxx     xxx   xxx   xxx    xxxx

What do I have to do?Please help.


<?php 
 $rows = array();
 if($result)
 {
      while($row=mysql_fetch_assoc($result)){
           $rows[] = $row;
      }
 }

<table height= "600" width="800">
<tr style="vertical-align: top; text-align:top display:inline-block">
<thead>   
      <tr>
      <td>FUll name</td>
      <td> Nickname</td>
      <td>Email Address</td>
      <td>Gender</td>
      <td>DOB</td>
      <td>BELT ID</td>
      <td>GROUP</td>  
      </tr>
  </thead> 
  <?php foreach ($rows as $row){?>
  <tr>
      <td><?php echo $row['fullname']?></td>
      <td><?php echo $row['nickname']?></td>
      <!--other fields here-->
      <td><?php echo $row['GROUP']?></td>  
  </tr>
  <?php }?>
</tr> 

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜