我想在C:中使用来自mysql数据库的Select查询
mysql_query(conn,"SELECT SI AS SUBSCRIBER_ID ,TG2 AS TAG_ID, SUM(CTR) AS NBR FROM (SELECT H.SUBSCRIBER_ID AS SI, TG.TAG_ID AS TG1,T.TAG_ID AS TG2, COUNT(TG.TAG_ID) AS COUNTER,CASE WHEN (TG.TAG_ID = T.TAG_ID) THEN COUNT(TG.TAG_ID) ELSE 0 END AS CTR from content_hits H left join CONTENT_TAG TG ON TG.CONTENT_ID = H.CONTENT_ID LEFT JOIN TAG T ON 1= 1 GROUP BY H.SUBSCRIBER_ID, TG.TAG_ID,T.TAG_ID) AS TAB GROUP BY SI,TG2");
之后,我想使用'NBR'填充一维数组。
我试过了:
result = mysql_store_result(conn);
while ((row = mysql_fetch_row(result)))
{
t[i]=*row['NBR'];
printf("%d",t[i]);
}
但它不起作用。
答案 0 :(得分:2)
您无法像t[i]=*row['NBR'];
那样按名称访问行列。使用例如fields = mysql_fetch_fields(result);
来获取列名并迭代fields数组以查找列ID“NBR”具有的列ID。然后可以在t[i]=row[id];
中使用此ID。这些都在mysql连接器doc http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-fields.html