Help With libmysql

Hey I'm trying to access my database to get the minimum and the maximum of the database. So I've written this code so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    MYSQL *sock;
    sock = mysql_init(0);

	//CONNECTION//
    if (mysql_real_connect(sock, host, user, pass, db, 0, NULL, 0))
         cout << "MySQL is Connected\n" << endl;
    else {
         cout << "Connection Failed: " << mysql_error(sock) << endl;
	}
	
	//Get Range Of Database//
	int E_min, E_Max, E1_max, E2_max, E3_max, E1_min, E2_min, E3_min;
	
	E_min = mysql_query (sock, "SELECT * FROM  `mdbase` ORDER BY  `mdbase`.`E3` ASC LIMIT 0 , 1");

	MYSQL_RES *resultEmin ;
	MYSQL_RES *resultEmax ;
	MYSQL_ROW row_Emin;
	MYSQL_ROW row_Emax;
	
	resultEmin= mysql_use_result(sock);
	row_Emin = mysql_fetch_row (resultEmin);
	
	E1_min = atoi (row_Emin [7]);
	E2_min = atoi (row_Emin [8]);
	E3_min = atoi (row_Emin [9]);
	
	E_Max = mysql_query (sock, "SELECT * FROM `mdbase` WHERE (E1 = (SELECT MAX(E1) FROM `mdbase`)) AND (E2 = (SELECT MAX(E2) FROM `mdbase`)) AND (E3 = (SELECT MAX(E3) FROM `mdbase`));");
	
	resultEmax = mysql_use_result(sock);
	row_Emax = mysql_fetch_row (resultEmax);
	
	E1_max = atoi (row_Emax [7]);
	E2_max = atoi (row_Emax [8]);
	E3_max = atoi (row_Emax [9]);


The minimum function return the minimum value. But the maximum finction makes the program crash. Is there any explanation to this? Thanks very much.
Topic archived. No new replies allowed.