Hello, In C you dont have named access to the columns as they are returned as an array of char*. The only solution would be to access it using its index value.
Like PHP, you have to do mysql_fetch_row() anyway. After that access the row by its index. If you prefer named access and dont mind a minute perdformance hit, then you can write your own function that takes FIELD_RES* structure and the name of the column. The function then loops thru each colum name and if found returns the char*. But do keep in mind that the pointer for the currenly FIELD structure changes in this way. HTH Karam --- Matthew Boehm <[EMAIL PROTECTED]> wrote: > What is the best way to access a specific field in > C? Its really easy in > PHP... > > PHP > ------- > $res = mysql_real_query($mysql,"SELECT col1, col2 > FROM table"); > while($row = mysql_fetch_row($res)) { > print $row['col1']; > print $row['col2']; > } > > Is the only way/best way to do the above in C by > using a nested for-loop? > Ex: > > fields = mysql_fetch_fields(res); > while((row=mysql_fetch_row(res)) { > for(x=0;x<numFields;x++) { > sprintf(output, "Column name: %s Column > Value: %s\n", > fields[x].name, row[x]); > } > } > > Seems painful and extra-loopy to do it in C. Is > there a better way? > > Thanks, > Matthew > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/[EMAIL PROTECTED] > > __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]