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 6352315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:10:45+00:00 2026-05-24T22:10:45+00:00

In the following code for retrieving data via a SQL query from the db,

  • 0

In the following code for retrieving data via a SQL query from the db, is there a way I can replace row[0] with fieldname. I am only enclosing the relevant part of the code

MYSQL_RES *resptr;
MYSQL_ROW row;

while ( ( row = mysql_fetch_row(resptr)) != NULL ) 
{
for (int i=0;i<8;i++)
string key = row[0];
 }  

row[0] is the trans_date column. the code works fine as it is right now, but is there a way to assign key by using the fieldname vs. having to remember all the field numbers.
thanks!

  • 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-05-24T22:10:46+00:00Added an answer on May 24, 2026 at 10:10 pm

    You can retrieve field names by doing

    field = mysql_fetch_field(resptr);
    std::cout << field->name;
    

    (Put in a while loop to loop through all field)

    But you can’t call row[fieldName]. What you can do though is define variables to map column names and numbers

    int id = 0;
    int trans_date = 1;
    // Code happening here
    std::cout << row[id] << " " << row[trans_date];
    

    UPDATE: You could always do something like this (using STL’s map):

    map<string, int> columns;
    int i = 0;
    while(field = mysql_fetch_field(resptr)){
      columns.insert(pair<string,int>(field->name, i++));
    }
    

    And then use row[columns["name"]];.

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

Sidebar

Related Questions

I have the following code on the client side for retrieving data from the
Using the following code, I'm retrieving a list of Integers from a DB and
I'm retrieving an IEnumerable list of properties via following code: BindingFlags bindingFlag = BindingFlags.Instance
Following code iterates through many data-rows, calcs some score per row and then sorts
I am getting the following error when retrieving data from a rest data source
I'm retrieving some data from Twitter using the code below Dim FilterData = follow=13,15
I have a query on retrieving data sent as JSON from a JavaScript, inside
I am retrieving HTML from a remote host with the following jQuery code var
I am retrieving results from twitter using jQuery using the following code: $(document).ready(function(){ var
The following code should find the appropriate project tag and remove it from the

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.