in mysql_* you could use the following to display a specific row and column:
mysql_result(3,2)
This would show 3rd row, second colum of result set.
I have a php pdo script to display some mysql data:
$sth = $db->prepare("SELECT name, surname FROM people");
$sth->execute();
$row = $sth->fetch();
$name=$row[name];
$surname=$row[surname];
The above would work well if I had a single result for the query. if I have multiple results, how could I fetch the name and suraname for a specific row and column.
So if I wanted row 11, column 0 and row 11, column 1 (name and surname from row 11) what would my syntax be?
Thanks as always for the advice.
If you need certain rows you should use
LIMITin your query to narrow returned dataset. Alternatively you can usefetchAll()but this uses more resources than needed, soLIMITwould both speed things up and reduce resource usage.PS: your array usage is wrong. You should be doing
$row['name'];not$row[name];. Or usefetch(PDO::FETCH_OBJ)(orfetchObject()) and then access properties like this$row->name;EDIT
fetchAll()returns array, with both numeric indexes and column name indexes. So accessing columns 0 and 1 of 11th row would look like this:or (which is better):
Note, rows are 0 indexed, hence
10not11.