Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

QT MySQL Daten addieren

Empfohlene Antworten

Veröffentlicht

hey hab eine allerletzte frage :rolleyes:

und zwar habe ich in meiner Datenbank zahlen hinterlegt und diese möchte ich alle addieren aber irgendwie hab ich keine ahnung wie ich das angehen soll...

hier mein versuch:


	QString ausgabe;

	MYSQL *connectionDB;

	MYSQL addDB;

	MYSQL_RES *result;

	MYSQL_ROW recordset_row;

	mysql_init(&addDB);

	connectionDB=mysql_real_connect(&addDB, "HOST", "BENUTZER", "PASSWORT", "DATENBANK", 0,0,0);


	string query= "SELECT Zahlen FROM verwaltung";

	mysql_query(connectionDB, query.c_str());

	result=mysql_store_result(connectionDB);

	int daten = mysql_num_rows(result);


        int a,b,c;

	for(int i=0; i < daten; i++)

	{

        a=recordset_row[0];

	recordset_row=mysql_fetch_row(result);

        b=recordset_row[0];

        c=a+b;

	}

problem ist nur recordset_row ist gespeichert als char* und kann die deswegen keinem int zuweisen .. bzw ich weiß net wie man das umwandelt

jemand ne ahnung?

hab das jetzt mal so probiert:


	QString str = recordset_row[0]

	int a,b,c;

	for(int i=0; i < daten; i++)

	{

	a = str.toInt(&ok, recordset_row[0]);

	recordset_row=mysql_fetch_row(result);

	b = str.toInt(&ok, recordset_row[0]);

	c= a+b;

	}

aber geht irgendwie nicht gibt es vllt in MySQL eine funktion die alles zusammenzählt? hatte schon gesucht aber nichts gefunden

hab das jetzt mal so probiert:

...

aber geht irgendwie nicht

Das ist ja auch totaler Quatsch. Du weist die "Summenvariable" bei jedem Schleifendurchlauf neu zu.

gibt es vllt in MySQL eine funktion die alles zusammenzählt? hatte schon gesucht aber nichts gefunden
Gibt es. Die Funktion hat allerdings den abwegigen Namen SUM.

omg >< ... hab alle möglichen funktionen versucht aber auf SUM bin ich net gekommen O.o ... naja vielen vielen dank für deine hilfe =)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.