从两个不同的表中选择并显示

i have 2 different table named productlist and rsales

the ff data in productlist are

id|pcode|
1 |1220 |

and the ff data in rsales are

id|total|total_discount|
3 |500  |      50      |

my problem is that i want to select data from two different table which is productlist and rsales and display it horizontally. i tried everything but it display vertically. the result must be something like this

id|pcode|total|total_discount|
1 |1220 |500  |   50         | 

this is my code so far but it only display data from single table

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("inventory", $con);



$result = mysql_query("SELECT * FROM productlist");

while($row = mysql_fetch_array($result))
  {
echo '<tr>';
echo '<td>'.$row['pcode'].'</td>';
echo '</tr>';
  }

mysql_close($con);
?>

there is no link between rsales and produclist but you can try like this, you will get all fileds from both the tables using this

$result = mysql_query("SELECT * FROM productlist,rsales");

Is the id difference between them offset by 2?If so,you can use Fluffeh answer like this:

select
 ffdata.pcode,
 rsales.total,
 rsales.total_discount
from
 ffdata
    join rsales
        on ffdata.id=rsales.id+2

You need to use a join in your SQL so that the data comes out in a single row in the results and is matched on the correct fields.

I wrote a lengthy Q&A about it a while back for just this sort of question which you will really do well to read, but in short, your query should look something like this:

select
    ffdata.pcode,
    rsales.total,
    rsales.total_discount
from
    ffdata
        join rsales
            on ffdata.id=rsales.id

This is assuming that you have a common key on the two tables that links the records.