Can't get the selected request to work

I want to use Select query from mysql database in C:

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");

      

After that, I want to use "NBR" to populate an array of one dimension.

I've tried this:

result = mysql_store_result(conn);

while ((row = mysql_fetch_row(result)))
{
  t[i]=*row['NBR'];
  printf("%d",t[i]);
}

      

But it didn't work.

+3


source to share


1 answer


You cannot access row columns by name, like you have t[i]=*row['NBR'];

. Use for example fields = mysql_fetch_fields(result);

to get the column names and iterate over the array of fields to find the NBR column ID. This identifier can then be used in t[i]=row[id];

. It's all in the mysql doc connectors http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-fields.html



+2


source







All Articles