0

I need your help, I have this table (image) and I want to put that data in columns per row like this fiddle, but I don't know how, I only know display in the same way like db table (rows). You know how can I do that?

enter image description here

This is the way for show data from MySQL that I use:

<?php 
    $sqlStr = "SELECT items.CA_id, items.item_id, items.item_Cant, items.CECO_cod,      items.item_desc, items.item_enduser
FROM items where CA_id = ".$CA_id;
    $sqlStrAux = "SELECT count(*) as total FROM items";

$aux = Mysql_Fetch_Assoc(mysql_query($sqlStrAux));
$query = mysql_query($sqlStr);  

    if($aux['total']>0){

        echo "</br></br>";
        echo "<div class='datagrid'>";
        echo "\t<table class=\"tablesorter\">\n";
        echo "<thead>";
        echo "<tr>
                <th>Item</th>
                <th>Cantidad</th>
                <th>CECO</th>
                <th>Descripción de solicitud</th>
                <th>Usuario final</th>              
              </tr>\n";
        echo "</thead>";      
        echo "<tbody>";
        while($row = mysql_fetch_assoc($query)){
      echo "\t\t<tr>
                    <td>".htmlentities($row['item_id'])."</td>
                    <td>".htmlentities($row['item_Cant'])."</td>
                    <td>".htmlentities($row['CECO_cod'])."</td>
                    <td>".$row['item_desc']."</td>
                    <td>".$row['item_enduser']."</td>
                </tr>\n";
    }
        echo "</tbody>";                  
        echo "\t</table>\n";
    }
        echo "</div>";
?>

I hope you understand, thanks.

user3810795
  • 162
  • 1
  • 17
  • You mean having them on separate tables? – rjpedrosa Jul 24 '14 at 18:38
  • Can you draw us a picture in paint or Excel or something so we can better understand what you want to achieve. The JSFiddle is a little vague. If you wanted to do them in a table then: http://fiddle.jshell.net/WqqJq/2/ But I don't think that is what you mean. – ZeroBased_IX Jul 24 '14 at 18:41
  • store data in a 2-dimensional array, apply transpose, then output table? – Fabricator Jul 24 '14 at 18:41
  • Sorry for that, i just updated the table in [fiddle](http://fiddle.jshell.net/MetCastle/WqqJq/) like i wanna do. – user3810795 Jul 24 '14 at 19:25
  • look at the answer here on transposing an array http://stackoverflow.com/questions/797251/transposing-multidimensional-arrays-in-php – cmorrissey Jul 24 '14 at 19:35

1 Answers1

1

Assuming you are asking how to flip the table sideways: Store the values in an array, and then echo the contents of each array per line, like so:

<?
while($row = mysql_fetch_assoc($query)){
    $itemID[] = htmlentities($row['item_id']);
    $item_Cant[] = htmlentities($row['item_Cant']);
    $CECO_cod[] = htmlentities($row['CECO_cod']);
    $item_desc[] = $row['item_desc'];
    $item_enduser[] = $row['item_enduser'];
}
echo "<table>";

echo "<tr><td>Item ID</td>";
for ($i=0; $i<count($itemID);$i++) {
    echo "<td>".$itemID[$i]."</td>";
}
echo "</tr><tr><td>Item Can't</td>";
for ($i=0; $i<count($item_Cant);$i++) {
    echo "<td>".$item_Cant[$i]."</td>";
}
echo "</tr><tr><td>Next row title...</td>";
...
...
echo "</table>";
?>
DanceSC
  • 521
  • 1
  • 4
  • 14