How to build a table and import data according to column?


I want to display data according to column but it is showing empty block in table. Here is my Code -

 <th id ='th1'>Animal</th>
    <th id='th2'>Flower</th>
<tr><td><?php echo $animalname ;?> </td></tr>
<tr><td><td><?php echo $flowerlname ;?> </td></td></tr>

Output i’m getting - I want to remove empty column

Animal | Flower      |
______|__Rose__ |

You’re going to need to show us more code than just that @chopraarpita92

You need to structure your tables properly into rows with the right number of cells in them.
Currently you have header not contained by a row. Then a row with a single column, followed by a row with two cells nested inside each other.
This is obviously invalid code.

Do it like this:

    <th id='th1'>Animal</th>
    <th id='th2'>Flower</th>
    <td><?php echo $animalname ;?></td>
    <td><?php echo $flowerlname ;?></td>

Thanks Paul,

I tried this but the thing is i hv huge database so when data will fetch from db then i want animal name in animal column only but your above mention code will take the data any give randomly. What i want is i’m writing th1 for column 1 heading so if i’m passing header to then data should only go to that column(i mean if in array i have (cat,horse,jasmine,rose,dog)then it will show flowername in flower column and animal name in animal column) is there anything what i’m relating like th1. header with data.

Animal Flower <?php echo $animalname ;?> <?php echo $flowername ;?>

Paul’s code basically cleaned up the invalid HTML table structure that you posted:

<tr><td><td><?php echo $flowerlname ;?> </td></td></tr>


 <td><?php echo $flowerlname ;?></td>

Give me a few minutes to review this topic and we can talk tables.

In the meanwhile, either post a link to a test page or supply more surrounding code, as @Gandalf requested, including screenshots, if they will help.

I’ll assume that you are ready when you post something more

Thanks Ronpat,

I 'm getting output like that-

i have nos in my database i need to check and show the no in db as the no belongs to which category. my code is as similar to above mention code. i want to remove empty space between column . in this picture you can see 26 is in 5ghz so it should cover the space near 2 rather than creating new row.

Please show the HTML including the php calls.

How do you query the database? How do you tell the database in which cells to display the data?

Apparently your table is being dynamically built by PHP and the PHP is building it incorrectly. If that is true, then this topic should be moved to the PHP category and you should provide the required PHP for examination.

@PaulOB showed how to structure a 2-row by 2-column table.

Please post a link to a working test page.

If you are unable to show us more code, then I recommend that you hire a contractor to troubleshoot your PHP for you privately.

If I understand, what you have is not tabular data, but more like two unrelated lists displayed side by side. That is, the rows have no meaning, but the columns do.

If you are using table tags to get a display like a table does by default IMHO it would be better to use more appropriate tags and style them to look similar to a table layout.


Hello ronpat,

It’s in my university’s server so difficult to send the link. I’m writing the code here -

test.php -
New Text Document.txt (927 Bytes)

The PHP is building the table incorrectly as shown by @SamA74 in post #3 and @PaulOB in post #4 and again mentioned in post #6.

The text file that you included shows the PHP that accesses the database and builds the table. That is very helpful. Thank you.

Who has the skill and permissions to fix the PHP on the server?

I am asking because we have shown you what is happening but you have made no attempt to change the PHP. It would be helpful if we communicate with the people who understand HTML and can modify the PHP code.

The table should be built so it is structured the way PaulOB showed in post #4. Until you change the PHP code to make that happen, your “expected” output is just wishful thinking.

I am not a PHP person, so I will move this topic to the PHP category. The people in that category are very good .

Thanks Ronpat

1 Like

Please answer this question so we understand what your skill level is and what your permissions are on the server, if any.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.