ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

How get data value from column record table db to variable arduino #55

Closed mydhitz closed 2 years ago

mydhitz commented 6 years ago

hi @ChuckBell i ask again, how get data from record table to variable in arduino.

New York Los Angeles Chicago Houston Philadelphia Phoenix San Diego Dallas San Antonio Detroit San Jose Indianapolis Disconnected.

i want my variable in arduino is..

char city1 = New York char city2 = Los Angeles char city3 = Chicago etc

i have field in database

Location Status
A1 0
A2 1
A3 1

and i use and modify this code to

    //do {
    for (int i=0;i<3;i++){  
      row = cur_mem->get_next_row();
      String results = row->values[0];
      int condition[i] = atoi(resultsc_str());
      Serial.println(condition[i]);
      if (condition[i] > 0){
         Serial.print("record 1 enable ");
         }
      else {
         Serial.print("record 1 disable ");
      }
        //}
    } //while (row != NULL);
    delete cur_mem;

when i run and show record A1, how to show record a2 and a3 in condition if, if record A1 have value 0 then disable is work and show value 0 in my serial, but if record A2 and A3 have value 1 then enable is not work

copterino commented 6 years ago

I would recommend you to take a course in C/C++ first, there are a lot of places where you can find good resources: such as www.learncpp.com or on youtube. No offense :) As for your code, row = cur_mem->get_next_row(); after this you should check if rowis valid:

if (row)
{
.....
}

Original code checked it with while (row != NULL) which you commented out. int condition[i] = atoi(resultsc_str()); this is not correct use just simple int variable:

int condition = atoi(results.c_str());
if (condition > 0){
....
mydhitz commented 6 years ago

oh thanks for answer and helpme, i just want to read second data from db and add to variable in my arduino, but show in serial is first data. and i use this code :


     do {   
         row = cur_mem->get_next_row();
         if (row != NULL) {
             strcpy(results, row->values[0]);
             Serial.print("> ");
             Serial.println(results);
            }
          } while (row != NULL);

          delete cur_mem;
ChuckBell commented 6 years ago

Do you still need help or can I close this issue?

Sent from my iPad

On Jul 19, 2018, at 4:53 AM, dito notifications@github.com wrote:

oh thanks for answer, i just want to read data from db and add to variable in my arduino

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.