Seuss Seuss - 10 days ago 6
MySQL Question

PHP MySQL vertical table

I have a horizontal table using PHP and MySQL now

table

How can I make a vertical table from this code?

<div class="content-loader">
<table cellspacing="0" width="100%" id="rank2" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Nick</th>
<th>Kredity</th>
<th>Body1</th>
<th>Body2</th>
<th>Cas</th>
<th>online</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance
FROM ranks
INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId
LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId
WHERE ranks.steamId = ?");
$stmt->execute(array($steamprofile['steamid']));

while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "<td>". $row['lastDisplayName']."</td><td>". $row['balance'] ."</td><td>". $row['points'] ."</td><td>". $row['points2'] ."</td><td>". $row['points2'] ."</td>";
}
?>
</tbody>
</table>
</div>

Answer

You could try this one

Just copy and paste the prepare and change the variables, same goes to execute

<div class="content-loader">

<?php
  require_once 'dbconfig.php';
  $stmt1 = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance FROM ranks INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId WHERE ranks.steamId = ?");
  $stmt2 = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance FROM ranks INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId WHERE ranks.steamId = ?");
  $stmt3 = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance FROM ranks INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId WHERE ranks.steamId = ?");
  $stmt4 = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance FROM ranks INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId WHERE ranks.steamId = ?");
  $stmt5 = $db_con->prepare("SELECT ranks.steamId, ranks.points, ranks.lastDisplayName, ranks.lastUpdated, ranksrussia2.points AS points2, uconomy.balance FROM ranks INNER JOIN ranksrussia2 ON ranks.steamId = ranksrussia2.steamId LEFT JOIN uconomy ON ranks.steamId = uconomy.steamId WHERE ranks.steamId = ?");

  $stmt1->execute(array($steamprofile['steamid']));
  $stmt2->execute(array($steamprofile['steamid']));
  $stmt3->execute(array($steamprofile['steamid']));
  $stmt4->execute(array($steamprofile['steamid']));
  $stmt5->execute(array($steamprofile['steamid']));

  ?>

<table cellspacing="0" width="100%" id="rank2" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<td>Nick</td>
<?php 
while($row = $stmt1->fetch(PDO::FETCH_ASSOC))
  {
      echo "<td>". $row['lastDisplayName']."</td>";
  }
 ?>
</tr>
<tr>
<td>Kredity</td>
<?php 
while($row = $stmt2->fetch(PDO::FETCH_ASSOC))
  {
      echo "<td>". $row['balance'] ."</td>";
  }
 ?>

</tr>
<tr>
<td>Body1</td>
<?php 
while($row = $stmt3->fetch(PDO::FETCH_ASSOC))
  {
      echo "<td>". $row['points'] ."</td>";
  }
 ?>

</tr>
<tr>
<td>Body2</td>
 <?php 
while($row = $stmt4->fetch(PDO::FETCH_ASSOC))
  {
      echo "<td>". $row['points2'] ."</td>";
  }

 ?>


</tr>
<tr>
<td>Cas</td>
 <?php 
while($row = $stmt5->fetch(PDO::FETCH_ASSOC))
  {
      echo "<td>". $row['points2'] ."</td>";
  }

 ?>

</tr>
<tr>
<td>Online</td>

</tr>
</thead>
<tbody>

</tbody>
</table>

</div>