Sandesh Rana
Sandesh Rana

Reputation: 81

How to echo table vertically when using PHP code?

I am trying to echo out the record of event in the website from database server. The code below presents the records in horizontal format however I want it as vertically.

Echo.php file

<?php
  //Connect to database
  $con=mysqli_connect("#", "#", "", "#");
  // Check connection
  if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

  //Query to select all publications from the 'files' table
  $result = mysqli_query ($con,"SELECT * FROM event ORDER BY event_date DESC LIMIT 4");

  //Echo out table
  while($row = mysqli_fetch_array($result))

  //Echo out the publication details
  {
  echo "<table class='table' border='0'>
<tr>
     <td>
        <a href='business_profile.php?id={$row['event_id']}'> ".$row['event_name'] ." </a>
        </td>
     <td>
     <img width='190' height='180' src='data:image/jpeg;base64,".base64_encode($row['event_pic'])."'/>
     </td>
     <td>" . $row['event_info'] . "</td>
</tr>";

  echo "</table>";
  }
   ?> 

Currently it presents,

event1 event1_pic event1_info

event2 event2_pic event2_info ..so on

However I want the code to present as below in a block

event1 event 2

event1_pic event2_pic

event1_info event3_pic

Upvotes: 0

Views: 1275

Answers (1)

Shockwave
Shockwave

Reputation: 412

the

<tr> 

tag is a table row. you can put multiple

<td> 

tags to create table cells on each row. Example:

<tr>
    <td>Row 1, Column 1</td>
    <td>Row 1, Column 2</td>
</tr>
<tr>
    <td>Row 2, Column 1</td>
    <td>Row 2, Column 2</td>
</tr>

This will quickly familiarize you with basic html table structure: http://www.w3schools.com/html/html_tables.asp

Upvotes: 2

Related Questions