-1

Want to print Participant information like firstName, organization from two different table. Query is working properly as it is giving desired results. But when I try to print fetched data, it returns an error.

function get_all_participant(){
  include 'connection.php';

  $sql = '
select p1.fname
     , p1.organization
     , p1.state
     , p2.created
  from participant p1
     INNER JOIN programme_participant p2 
 ON p1.id = p2.participant_id
';
  try{
    $results = $db->prepare($sql);
    $results->execute();
  } catch (Exception $e){
    echo "Error! " . $e->getMessage() . "<br/>";
    return false;
  }
  return $results->fetch();

}

<?php foreach (get_all_participant() as $item){
         echo $item['fname'];
  }?>

Output(error):

Warning: Illegal string offset 'fname'

GKumar
  • 81
  • 1
  • 1
  • 11

1 Answers1

0

Try to use

$result = $results->fetchAll();

if query return multiple records then fetch function will not work