Jump to content

echoing php in a table


dean7

Recommended Posts

Hi all, ive got a script witch im wanting to echo all the selected users in a table..

 

It selects and echos the users but just dosent add on to the table.

 

<?php
$themembers = mysql_query("SELECT * FROM users WHERE crew = '$user->crew'");
	$ammoutmembers = mysql_num_rows($themembers);
?>
<html>
<head>
<title>Crew Members || SD</title>
</head>
<body>
<?php
if ($crewstuff->boss == $username || $crewstuff->coowner == $username || $crewstuff->underboss == $username){
?>
<table width='80%' align='center' class='table' cellpadding='0' cellspacing='0' border='1'>
<tr>
<td class='header' colspan='3' align='center'>Current Crew Members</td>
</tr>
<tr>
<td class='omg' align='center' width='40%'>Username</td><td class='omg' align='center' width='30%'>Rep</td><td class='omg' width='30%' align='center'>Kick</td>
</tr>
<?php
if ($ammoutmembers != "0"){
while ($member11 = mysql_fetch_object($themembers)){
?>
<tr>
<td width='40%'><?php echo("<a href='profile.php?viewuser=$member11->username' target='mainFrame'>$member11->username</a>"); ?></td><td width='30%'><?php echo ("".number_format($member11->rep).""); ?></td><td width='30%'><?php echo("<a href='?action=members&kick=$member11->username'>Kick</a>"); ?></td>
</tr>
<tr>
<td colspan='3' class='omg' align='center'>Any member kicked is logged.</td>
</tr>	
</table>	
<?php
} // $member11
}// $ammoutmembers
}elseif ($crewstuff->member == $username){
echo ("Your not being here , without being staff.");
}
?>

 

Is there way I can make it so it will be something like this layout:

 

Username          | Rep | Kick

----------------------------------

username          | 0    | Kick

username          | 0    | kick

 

For each user thats echoed?

 

Thanks for help given :D

Link to comment
https://forums.phpfreaks.com/topic/219901-echoing-php-in-a-table/
Share on other sites

The problem is that within your while loop that iterates through the result set... you have the </table> end tag.

You only want to loop this: <tr><td></td><td></td><td></td></tr>

Row > cell cell cell

 

You just want to do like:

 

<?php
if ($crewstuff->boss == $username || $crewstuff->coowner == $username || $crewstuff->underboss == $username){
?>
<table>
<thead>
   <th>User</th>
   <th>Rep</th>
   <th>Kick</th>
</thead>
<tbody>
    <?php
if ($ammoutmembers != "0"){
    while ($member11 = mysql_fetch_object($themembers)){
?>
   <tr>
        <td><?php echo("<a href='profile.php?viewuser=$member11->username' target='mainFrame'>$member11->username</a>"); ?></td>
        <td><?php echo ("".number_format($member11->rep).""); ?></td>
        <td><?php echo("<a href='?action=members&kick=$member11->username'>Kick</a>"); ?></td>
   </tr>
   <?php
      } // $member11
}// $ammoutmembers
?>
</tbody>
</table>
<?php
}elseif ($crewstuff->member == $username){
      echo ("Your not being here , without being staff.");
}
?>

The problem is that within your while loop that iterates through the result set... you have the </table> end tag.

You only want to loop this: <tr><td></td><td></td><td></td></tr>

Row > cell cell cell

 

You just want to do like:

 

<?php
if ($crewstuff->boss == $username || $crewstuff->coowner == $username || $crewstuff->underboss == $username){
?>
<table>
<thead>
   <th>User</th>
   <th>Rep</th>
   <th>Kick</th>
</thead>
<tbody>
    <?php
if ($ammoutmembers != "0"){
    while ($member11 = mysql_fetch_object($themembers)){
?>
   <tr>
        <td><?php echo("<a href='profile.php?viewuser=$member11->username' target='mainFrame'>$member11->username</a>"); ?></td>
        <td><?php echo ("".number_format($member11->rep).""); ?></td>
        <td><?php echo("<a href='?action=members&kick=$member11->username'>Kick</a>"); ?></td>
   </tr>
   <?php
      } // $member11
}// $ammoutmembers
?>
</tbody>
</table>
<?php
}elseif ($crewstuff->member == $username){
      echo ("Your not being here , without being staff.");
}
?>

Thanks, changed my code and it worked :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.