How to display the value of a query in C?

Asked

Viewed 84 times

-1

Rephrasing the question:

I have a table in Mysql where I need to display the person’s name as soon as they type their ID. I’m making a code where I just try to do the search to see if you’re searching normally, but I can’t display this value on the screen.

Follows the code:

int main(){

    MYSQL conexao;
    int res;
    int esco = 2;
    char query[100];
    mysql_init(&conexao);
    if ( mysql_real_connect(&conexao, "localhost", "root", "", "teatro", 0, NULL, 0) ){
        sprintf(query,"select tb_aluno_nome from tb_aluno where tb_aluno_rg = '999999999';");
        res = mysql_query(&conexao,query);
        if (!res)
            printf("nome: %i",res);
        system("pause");
        return(0);

    }
}
  • put the code of what has already been done or explain the situation better, to help visualize your problem

  • Maybe taking out the ! of if (!res)... the ! means "negative" (zero, null or empty), which seems to me to be the opposite of what you want.

  • In fact, the ! means false

  • In fact, the ! means not, nay? :-) -> C Operators

1 answer

0

Forehead there, my good!

int main() {
   MYSQL conexao;
   int res;
   int esco = 2;
   char query[100];
   mysql_init(&conexao);
   if ( mysql_real_connect(&conexao, "localhost", "root", "", "teatro", 0, NULL, 0) ){
       sprintf(query, "select tb_aluno_nome from tb_aluno where tb_aluno_rg = '999999999';");
       res = mysql_query(&conexao,query);
       if (res) {
           campos = mysql_fetch_fields(res);
           for (i=0; i < mysql_num_fields(res); i++) {
               printf("%s", (campos[i]).name);
           }
       }
   }
   mysql_close(&conexao);
   system("pause");
   return(0);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.