使用php变量查询语法以从两个MySQL表中进行选择

I currently have a family tree database. I get the data to display by doing:

$sql = "SELECT * FROM persons WHERE ref='$personID'";

This works nicely. However, I've recently added another table called census_data. I'm trying to query this table at the same time as the persons table without success. I've tried doing this:

$sql = "SELECT * FROM persons, census_data 
WHERE persons.$personID = census_data.$personID ";

The error I get says:

Unknown column 'persons.405' in 'where clause'.

I'm far from competent with databases, but this error seems to be talking about columns, while it is a row that I'm looking for. Obviously I've messed up.

How do I do this?

You need to join persons and census_data and also limit data by the personID:

$sql = "SELECT * FROM persons, census_data 
WHERE persons.ref = '$personID' AND persons.ref = census_data.person_id_column_name";

The way you have it the query is looking for a column name equal to your personId (405 in your example) instead of looking for a personId of 405.