Hi,

I need to display 4 items from a MySQL database in a 2x2 table (2 columns, 2 rows) i know how display just rows and columns, but how would I do both?

thank you

Recommended Answers

All 4 Replies

Have you considered using embedded for loops?

Have you considered using embedded for loops?

could you give me an example please?

please specify the fields you want to display in the table.

$strHtml = '<table class="blah">';
$intCount = 0;
for($i = 0; $i < 2; $i++) {
$strHtml .= '<tr>';
for($j = 0; $j < 2; $j++) {
$strHtml .= "<td>{$arrResult[$intCount]}</td>";
$intCount++;
}
$strHtml .= '</tr>';
}
$strHtml .= '</table>';

That is a very untidy example. I never usually mix HTML and PHP, so to better the above, I would be inclined to template it and have a separate template for each table cell. But that should be enough to work with and improve upon.

R.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.