Skip to content Skip to sidebar Skip to footer

Get Data From Backend Into Three Columns In One Row

I am making a function in which the data I am trying to get comes in two columns in one row and there are multiple rows generated. The data is arranged in table and I tried to make

Solution 1:

Here you go :) Modulus operator helps here.

http://en.wikipedia.org/wiki/Modulo_operation

$html = '<table class="table table-bordered"><table>';
$r = 0;
$columns = 3;
foreach ($productsas$pr) {
    if ($r%$columns == 0) $html .= '<tr>';
    $html .= '<td>';
    $html .= '<strong>'.$pr->name.'</strong><br />';
    $html .= $pr->price.'<br />';
    $html .= $this->product_barcode($pr->code, 30, 147);
    $html .= '</td>';
    if ($r%$columns == $columns || $r++ == count($products)-1) $html .= '</tr>';
}
$html .= '</tbody></table>';

Post a Comment for "Get Data From Backend Into Three Columns In One Row"