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!
You can retrieve field names by doing
(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 numbersUPDATE: You could always do something like this (using STL’s map):
And then use
row[columns["name"]];.