Hi there,

I am still learning php and would be glad if somebody help me to understand the processes of the following select query.

The below stated select query does not contain any results (rows) in its result set if some variables contain no entry in the database (in the respective row). Why is this the case and how can I still retrieve results even if some variables contain no entries?

Here is the query

p2g.id and p2gtext are part of the p2g table
name, email are part of the author table

$sql = 'SELECT p2g.id, p2gtext, name, email
FROM p2g INNER JOIN author
ON authorid = author.id';
$result = $pdo->query($sql);
catch (PDOException $e)
$error = 'Error fetching places to go: ' . $e->getMessage();
include 'error.html.php';

if ($result->rowCount() === 0) {
$output = 'Select query contains no entries.';
include 'p2g.html.php';
include 'output.html.php';

In the table "author" are no entries made. Therefore the variables name and email are empty. The table p2g contains entries. If I run the query no results are shown (the if statement is applied)

I get the results if I do not "Inner Join" the author table, and therefore all variables have entries in respective rows.
I also get the results if I insert data into the author table. But only the results will be show which have an entry in ALL variables (in the respective row).

Why there is an entry needed in all variables for a select query to show the results?
And how can I alter the select query that results are still shown, even if not all variables contain an entry for the respective row?

Please email if you need better description of the problem

Thanks for help in advance!