0

Is it normal that I get a result with as many arrays as the number of rows in my table when I do a PDO request with the code below :

$query3 = $bdd->prepare('select id, MAX(priority), question from questions');

$query3->execute();

$row = $query3->fetch(PDO::FETCH_ASSOC);

print_r($row);

Here is the result I get :

Array ( 
    [id] => 2 
    [MAX(priority)] => 117820
    [question] => Question ?
 )
Array ( 
    [id] => 2 
    [MAX(priority)] => 117820
    [question] => Question ? 
) 
Array ( 
    [id] => 2 
    [MAX(priority)] => 117820
    [question] => Question ? 
) 
Array ( 
    [id] => 2
    [MAX(priority)] => 117820
    [question] => Question ? 
) 
Array ( 
    [id] => 2 
    [MAX(priority)] => 117820
    [question] => Question ? 
)

Is there something I should do differently to get only one result in $row?

Thanks

gustavodidomenico
  • 4,640
  • 1
  • 34
  • 50
tienow
  • 171
  • 12
  • It's only returning one row. It looks to me like you're running the same query 5 times. – Barmar Aug 21 '15 at 23:24
  • That's not a result with 5 arrays. That's you printing the same array 5 times. – Barmar Aug 21 '15 at 23:25
  • 1
    BTW, the `id` and `question` won't necessarily be the one with the maximum priority. See http://stackoverflow.com/questions/7745609/sql-select-only-rows-with-max-value-on-a-column?rq=1 for how to do that. – Barmar Aug 21 '15 at 23:26
  • Oups, you're right, stupid question. Sorry and thanks – tienow Aug 21 '15 at 23:27

0 Answers0