Matthew Boehm wrote:

What is the best way to access a specific field in C? Its really easy in
PHP...


http://dev.mysql.com/doc/mysql/en/mysql_fetch_row.html
you won't have the hash-table feature offered by PHP, but nothing stop you to do the same.


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?

PHP hide that loop somewhere, but it use the C api anyway...
If you know your query you can access row[0] or row[2] directly, isn't it ?
If you are familiar with C++, you could program something like row["col1"]. (does anyone know if the c++ api offer that sort of feature ? )


--
Philippe Poelvoorde
COS Trading Ltd.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to