August C. August C. - 19 days ago 6
PHP Question

From a query, place the information in horizontal manner on a table

I have the following query

$res = mysql_query ("SELECT * FROM books",$conexion);
while($row=mysql_fetch_array($res))

echo $row["Name"];

I want to place it in horizontal manner in a table like this

Name1 Name2 Name3 Name4
Name5 Name6 Name7 Name8
Name9 Name10 Name11 Name12

instead of

Name1
Name2
Name3
Name4...

Answer

This should give you an idea of what you need to look at. Basically you are looping through the results you have collected and displaying them inside a table row. Each result will be inside it's own cell within the row.

<table>
  <tr>
    <?php 
    foreach( $result as $key )
    {
      echo "<td>$key</td>";
    }
    ?>
  </tr>
</table>

You will need to adjust the array supplied $array but it is the basis of what you need.

Comments