Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:31:01+00:00 2026-06-14T14:31:01+00:00

in mysql_* you could use the following to display a specific row and column:

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:31:02+00:00Added an answer on June 14, 2026 at 2:31 pm

    If you need certain rows you should use LIMIT in your query to narrow returned dataset. Alternatively you can use fetchAll() but this uses more resources than needed, so LIMIT would both speed things up and reduce resource usage.

    PS: your array usage is wrong. You should be doing $row['name']; not $row[name];. Or use fetch(PDO::FETCH_OBJ) (or fetchObject()) 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:

    $dataArray = $sth->fetchAll();
    $name = $dataArray[10][0];
    $surname = $dataArray[10][1];
    

    or (which is better):

    $name = $dataArray[10]['name'];
    $surname = $dataArray[10]['surname'];
    

    Note, rows are 0 indexed, hence 10 not 11.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could use some help (preferably a dummy's guide) to updating the following table:
Based on this code below I use for regular mysql, how could I convert
I've seen in the code I'm working on, the following: foreach( $mysql_result as $row
Good day. I could really use your help on this one. I have a
I'm a novice MySQL user so could really use a little advice here. I've
In MySql I could have a table with an auto increment column and insert
If anyone could recommend a good book for learning mySQL as well, that would
I have the following mysql query. Could you please tell me how to write
I'm just wondering how I could display my last 200 mysql entries in php
Is there a way that this full-text searching query could be translated from MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.