user3243925
user3243925

Reputation: 271

PHP + Html tables displaying correctly info

I'm currently trying to show some categories which come from database into tables. But I want the categories to be displayed this way:

    Animals        |   Other    |   Other    --> reached end of DIV, 
    Restaurants    |   Other    |   Other    --> the info must continue in another
    Houses         |   Other    |   Other    --> line
------------------------------------------------------
    Other          |
    Other          |

So my logic is to have variables to count $rows & $cols..but this won't work for every screen sizes..so I need a better approach.

The following code is just an example of the logic.

$categories = $all_categories();

$rows = 0;
$cols = 0;

$output = "<div><table>";

for($i = 0; $i <= count($categories) - 1; $i++){
    $output .= "<tr><td>" . $categories[$i]['name'] . "</td></tr>";
}

$output .= "</table></div>";

echo $output;

Is it possible to the table to detect that it has no more space and continue the <td> in next line? Here's also the jsfiddle: http://jsfiddle.net/G3fUw/

Edit: Solved, just needed to change this two lines.

<tr style='display: inline-block'>
<td style='display: inline-block'>

Upvotes: 1

Views: 49

Answers (1)

Arjun
Arjun

Reputation: 1439

By default the td has display:inline-block property so, it will never break when you reach end of DIV. so you can use display:block property for td,tr and table, or you can use DIV with float:left instead of table.

Upvotes: 1

Related Questions