So far everytime i use to make a select query using pdo, i used a while loop to echo all the result. I never has a single problem. But what I am looking to do know is just echo one record. Let’s say the record of the 23rd line of my table. So what I a doing is the following but i have this error: Notice: Undefined offset: 23 in /myFilePath/file.php
$qry_que= $connexion->query('SELECT * FROM table ORDER BY somefield';
$row = $qry_que->fetch(PDO::FETCH_ASSOC);
echo $row[23]['somefield'];
Do note that my table has more than 100 lines… Thank you in advance for your help. Cheers. Marc.
You cannot get the 24th row by doing
$row[23].You’ll have to use a
WHEREclause in your SQL query in order to get only the row you want.Moreover, it will be a lot better on a performance point of view (think about your query when your database has 10 millions rows…)