C does not actually support basic arrays of values, such as (I assume you think) PHP. The closest thing you could get is to get an array of column names, search for the one you need, and use this index. For instance:
mysql_query(_MySQLConnection, query); MYSQL_RES *result = mysql_store_result(_MySQLConnection); unsigned int num_fields = mysql_num_fields(result); MYSQL_ROW row; MYSQL_FIELD *field; unsigned int name_field; char *field_name = "name"; char *headers[num_fields]; for(unsigned int i = 0; (field = mysql_fetch_field(result)); i++) { headers[i] = field->name; if (strcmp(field_name, headers[i]) == 0) { name_field = i; } } while ((row = mysql_fetch_row(result))) {
source share