in DB i have two tables named my one and two.in table one there is a colum named by name and in table two there is colum named by address. when i run the query it show the result but the problem with this is that it show same result two times. can any one pleaze help me out.

in database table is like that
name address
ali1 hyderabad
hyder1 karachi

<?

$cn=mysql_connect("localhost","root");
mysql_select_db("test",$cn);

// Make a MySQL Connection
// Construct our join query
$query = "SELECT one.name,two.address FROM one,two";
	 
$result = mysql_query($query) or die(mysql_error());



echo " name "."address";
echo "<br />";

while ($row=mysql_fetch_array($result)){

	

	echo $row['name']. " - ".$row['address'];

echo "<br />";

}	

?>

result

name address
ali1 - hyderabad
hyder1 - hyderabad
ali1 - karachi
hyder1 - karachi

you should have an identifier on one and two that tie the two tables together like an id, or the name.
your query would look something like

$query="SELECT one.name,two.address FROM one,two where one.name=two.name";
// or some identifying field that ties that particular address to that particular name
$query="SELECT one.name,two.address FROM one,two where one.id=two.id";

it's a little more complex than that but you need to tie the address to the name record in some other way

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.