I have two tables customer
and customer_transaction
. Both have common customer_id
, but customer_transaction
also has a field description that I want to return with my result, based on the common customer_id.
The result works correctly, but omits the customer_id for all records that don't have both customer_id and customer_transaction. description as per image. I am sure that I am missing something small here.
A portion of the relevant code. I seem to think the problem lies in the SELECT statement.
$sql = "SELECT * FROM customer LEFT OUTER JOIN customer_transaction ON customer. customer_id =customer_transaction. customer_id WHERE customer.customer_group_id = $input";
$sth = $pdo->prepare($sql);
$sth->bindParam(':start',$start,PDO::PARAM_INT);
$sth->bindParam(':length',$length,PDO::PARAM_INT);
$sth->bindParam(':query',$query,PDO::PARAM_STR);
$sth->execute();
foreach ($sth->fetchAll(PDO::FETCH_ASSOC) as $row) {
$phpvar = "$row[description] "; //creat variable for descriptio so as to limit the length using substr
echo '<tr>';
echo '<td>'. $row['customer_id'] . '</td>';
echo '<td>'. $row['company_name'] . '</td>';
echo '<td>'. $row['firstname'] ." ". $row['lastname'] .'</td>';
echo '<td>'. $row['email'] . '</td>';
echo '<td>'. $row['telephone'] . '</td>';
echo '<td>'. $row['customer_id'] . '</td>';
echo '<td>'. $row['customer_group_id'] . '</td>';
echo '<td>'. substr($phpvar,0) . '</td>'; //Limit the length of the transactions here
echo '<td width=250>';