# Avoid repetitive code when creating tables from MySQL results

**URL:** https://forum.kirupa.com/t/avoid-repetitive-code-when-creating-tables-from-mysql-results/300280
**Category:** programming
**Created:** [November 18, 2009, 5:54pm UTC](https://forum.kirupa.com/t/avoid-repetitive-code-when-creating-tables-from-mysql-results/300280 "2009-11-18T17:54:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![imagined](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@imagined](https://forum.kirupa.com/u/imagined)
#### Post date: [November 18, 2009, 5:54pm UTC](https://forum.kirupa.com/t/avoid-repetitive-code-when-creating-tables-from-mysql-results/300280/1 "2009-11-18T17:54:07Z")

</div>

I often find myself (as I’m sure a lot of you do) creating tables from MySQL results. For example, a contacts table, an addresses table, etc.

Sometimes I do it manually, you know the whole

```php
query = 'SELECT * FROM table WHERE blah blah';
$result = mysql_query($query)
while($row=mysql_fetch_array($result))
$table .= '<tr>';
$table .= '<td>'.$row['id'].'</td><td>'.$row['name'].'</td>';
$table .= '</tr>';

```

thing

I have created some basic functions to tackle this repetitive code. In fact, I’m gonna create one right now.

Could you please share your solution to avoid similar code when displaying MySQL results?
