Q: How to access PDO results when table names are used in the SQL query? I recently had to change an SQL query to query multiple tables and started specifying the table names with the column names.
$results = $db->query('SELECT categories.name, channels.description, channels.name FROM categories JOIN channels ON categories.id = channels.category ORDER BY RANDOM() LIMIT 4');

However now I have a problem that the rest of the code doesn't work even though I updated it to use the table names with the column names.
<h3><?php echo $row['channels.name']; ?></h3>

How do I specify table name with column names in this way? The SQL query itself is fine but I don't understand how to echo the results?

A: The table name is unlikely to carry through to the output. Instead, alter the name of one of the columns with an alias, such as:
$results = $db->query('SELECT categories.name as cat_name, channels.description, channels.name FROM categories JOIN channels ON categories.id = channels.category ORDER BY RANDOM() LIMIT 4');

Then when referencing the columns, you refer to 
<h3><?php echo $row['name']; ?></h3>
<h3><?php echo $row['cat_name']; ?></h3>

Etcetera.

A: The documentation says:

The name of a result column is the value of the "AS" clause for that column, if there is an AS clause. If there is no AS clause then the name of the column is unspecified and may change from one release of SQLite to the next.

So if you want to access result columns by name, you have to use AS.
