How can I combine this code better? PHP
<pre><code>echo "&lt;table class='songlist'&gt;\n&lt;tr&gt;";
$array = mysql_fetch_assoc($result);
foreach ($array as $key=&gt;$value) {
    if($config['nicefields']){
    $field = str_replace("_"," ",$key);
    $field = ucwords($field);
    }

    $field = columnSortArrows($key,$field,$orderby,$sort);
    echo "&lt;th&gt;" . $field . "&lt;/th&gt;\n";
}
echo "&lt;/tr&gt;\n";

mysql_data_seek($result,0);

$tr_class = "class='odd'";

if(isset($_POST['search']))
{

    $search = mysql_real_escape_string($_POST['search']);

    $sql = mysql_query("SELECT * FROM citysongs WHERE artist LIKE '$search'");

    while($row = mysql_fetch_assoc($sql)) {
        echo "&lt;tr ".$tr_class."&gt;\n";
            echo "&lt;td&gt;" .$row['id']. "&lt;/td&gt;";
            echo "&lt;td&gt;" .$row['title']. "&lt;/td&gt;";
            echo "&lt;td&gt;" .$row['artist']. "&lt;/td&gt;";
            $empty = $row['chords'];
            if(!empty($empty)) {
                echo "&lt;td&gt;&lt;a href=" .$row['audio']. " target='_blank'&gt;Listen&lt;/a&gt; | &lt;a href=" .$row['chords'].  " target='_blank'&gt;Chords&lt;/a&gt; | &lt;a&gt;Add to SetList&lt;/a&gt;&lt;/td&gt;\n";
            }
        echo "&lt;/tr&gt;\n ";

        if($tr_class == "class='odd'"){
            $tr_class = "class='even'";
        }else{
            $tr_class = "class='odd'";
        }
    } 
} else {
        while($row = mysql_fetch_assoc($result) ){
            echo "&lt;tr ".$tr_class."&gt;\n";
                echo "&lt;td&gt;" .$row['id']. "&lt;/td&gt;";
                echo "&lt;td&gt;" .$row['title']. "&lt;/td&gt;";
                echo "&lt;td&gt;" .$row['artist']. "&lt;/td&gt;";
                $empty = $row['chords'];
                if(!empty($empty)) {                
                    echo "&lt;td&gt;&lt;a href=" .$row['audio']. " target='_blank'&gt;Listen&lt;/a&gt; | &lt;a href=" .$row['chords'].  " target='_blank'&gt;Chords&lt;/a&gt; | &lt;a&gt;Add to SetList&lt;/a&gt;&lt;/td&gt;\n";
                }
            echo "&lt;/tr&gt;\n";

            if($tr_class == "class='odd'"){
                $tr_class = "class='even'";
            }else{
                $tr_class = "class='odd'";
            }
        }
    }

echo "&lt;/table&gt;\n";
</code></pre>
