$dashim = "SELECT `id`, `name`, `dash` FROM `dashim` ORDER BY `id` DESC LIMIT 5"; $result = mysql_query($dashim); $dashim_s = "SELECT `id`, `replace`, `file` FROM `smilles`"; $result_s = mysql_query($dashim_s); while($dash = mysql_fetch_array($result)) { while($dash_s = mysql_fetch_array($result_s)) { $dash['dash'] = str_replace($dash_s['replace'], $dash_s['file'], $dash['dash']); } echo("<b>".$dash['name'].":</b> ".$dash['dash']."<br />"); }