you should probably ask 2 seperate questions in 2 seperate posts. But....
1.) Use preg_replace instead of eregi_replace. You can check a valid web address with that function.
2.) $query = SELECT a.field_one, a.field_two, b.field_three, b.field_four FROM column_one a, column_two b WHERE ...