c언어 테트리스 랭킹 점수(mysql연동) 해결방법 알려주실수 있나요?
void rank(void) {
system("cls");//화면을 지움
system("mode con: cols=70 lines=40");//콘솔창 크기를 조절
MYSQL* connection = NULL;
MYSQL conn = { 0 };
MYSQLRES* sqlresult;
MYSQL_ROW row = { 0 };
char query[255] = { 0 };
// char name[12] = { 0 };
char score[30] = { 0 };
char id[12] = { 0 };
char passwd[80] = { 0 };
int x = 3;//x좌표 값
int y = 2;//y좌표 값
int num = 0;//순위 변수
int query_stat = 0;
mysql_init(&conn);
connection = mysqlrealconnect(&conn, DB_HOST,
DBUSER, DBPASS, DB_NAME, 3306, (char*)NULL, 0);
if (connection == NULL) {
fprintf(stderr, "error : %s", mysql_error(&conn));
return 1;
}
mysql_query(connection, "select * from log2");//연결이 되면 log2테이블을 불러옴
mysql_query(connection, "select id, score from log2 ORDER BY 3 DESC");//log2테이블에서 내림차순
querystat = mysqlquery(connection, query);
gotoxy(x, y); printf("\t\t아이디\t\t 점수");
y = y + 2;
gotoxy(x, y); printf("=============================================================");
sprintf(query, "insert into log2 value" "(%s, %d)", id, score);//query에 id와 점수를 삽입
mysql_query(connection, query);
sqlresult = mysqlstoreresult(connection);//mysqlstore_result()를 이용하여 연결된 정보를 메모리에 저장
while ((row = mysqlfetchrow(sql_result)) != NULL) {
y = y + 1;
if (num <= 5)
{
gotoxy(x + 5, y); printf("%s", row[0]);
gotoxy(x + 10, y); printf("%10s", row[2]);
}
}
mysqlfreeresult(sql_result);//메모리 해제
_getch();//키의 입력을 받음
while (kbhit()) getch();//키 값을 버림
}

게임이 끝난 점수는 150점인데 저장되는 점수는 20점만 저장이 되서 끝난 점수 그대로 저장이 될려면 어떤부분을 수정해야 하는지, 해결 방법 알려주세요ㅠㅠ
안녕하세요
직접 해보질 못해서 소스 분석이 조금 힘들긴 하지만, 눈으로만 보면 점수를 update 해주는 부분이 없는것 같습니다.
log2 테이블이 점수를 저장한 테이블 인것이죠? log2 테이블에 id가 키로 지정되어있지 않은것같은데(abc가 계속 조회되는것으로요)
먼저 log2 테이블에 id를 키로 주고
sprintf(query, "insert into log2 value" "(%s, %d)", id, score);//query에 id와 점수를 삽입
위의 소스를 실행하기전에 해당id 로 row가 있는지 확인하고 있으면 update 없으면 insert 를 하셔야할것 같습니다.