Autor Beitrag
-delphin-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Mi 14.06.06 15:34 
Hi, von mir ne ganz einfache Frage: Ich habe eine lange Tabelle, bei der in der Spalte 'Art' ab und zu 'Brand' steht. Wie finde ich per SQL-Befehl die Anzahl der Brände?
Also SELECT Art FROM Einsatz WHERE Art = Brand liefert mir das ja nicht so einfach. Dafür gibts eine Funktion, die die Anzahl liefert. Wäre nett, wenn die mir einer geben könnte, danke ;)


Moderiert von user profile iconUGrohne: Topic aus Datenbanken verschoben am Sa 24.06.2006 um 07:59
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 14.06.06 15:36 
ausblenden SQL-Anweisung
1:
SELECT count(*) FROM Einsatz WHERE Art = Brand					
-delphin- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Mi 14.06.06 15:43 
hm also ich hab jetzt sowas hier zustande gebracht:

$test = mysql_query(" SELECT COUNT(Art) FROM Einsatz WHERE Art = 'Brand' ");
-delphin- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Mi 14.06.06 15:46 
hmm bekomme ich als fehler: Resource id #6
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 14.06.06 15:57 
Probiere es mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
  mysql_query.SQL.Text := 'SELECT COUNT(Art) as Anzahl FROM Einsatz WHERE Art = ''Brand''';
  mysql_query.open;
  ShowMessage(mysql_query.fieldbyname('Anzahl').AsString);

Alles ungetestet.
-delphin- Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 200



BeitragVerfasst: Mo 19.06.06 19:10 
oh mann dieser resouce id fehler kommt ständig, selbst bei einfachsten sachen wie

$sqltest = mysql_query( " SELECT Leiter FROM Einsatz " );
echo $sqltest;

mittlerweile hab ich resource id # 6; #7 und #8 gehabt^^
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 21.06.06 08:30 
Hallo,

Deine Frage hat mit Delphi nichts zu tun, sondern ist PHP-spezifisch.

Um die Anzahl der Datensätze zu erhalten musst Du folgendermaßen vorgehen:
ausblenden SQL-Anweisung
1:
2:
3:
4:
5:
6:
$sqltest = mysql_query("SELECT COUNT(Art) FROM Einsatz WHERE Art='Brand'"); 
if ($sqltest)
{
  $erg=mysql_fetch_row($sqltest);
  print "Anzahl Brände: ".$erg[0];
}


Ein Blick in die PHP-Hilfe hätte in diesem Fall auch nichts geschadet.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
Chaosworld
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 49



BeitragVerfasst: Fr 23.06.06 22:38 
Wie jasocul es sagte war schon richtig:
user profile iconjasocul hat folgendes geschrieben:
ausblenden SQL-Anweisung
1:
SELECT count(*) FROM Einsatz WHERE Art = Brand					


es muss nur:

SELECT count(*) FROM Einsatz WHERE Art = 'Brand'

heissen.
es muss count(*) heissen, da bei count die Datensätze gezählt werden, und nciht die einzelnen Felder. Somit wird z.B. COUNT(Art) nicht klappen. Und wenn man WHERE Art = Brand schreibt, sucht der die Datensätze, bei der das Feld Art gleich dem Feld Brand ist, und dass gibt es nicht!

Hoffe das hilft dir

Chaosworld
Demonking
ontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 42

Win XP
Delphi, Delphi 2005 Prof.
BeitragVerfasst: Sa 24.06.06 02:35 
beim aufrufen nie das mysql_query vergessen ^^
und obwohl das hier im forum so aussieht aber (*) <-- ist kein leerzeichen und soll auch keins sein :P
Und mit Delphi hat das wirklcih nix zutun :/ echo gibt es net in delphi sowas kommt dann in offtopic :P

$result=mysql_query("SELECT (*) as anzahl WHERE Art=Brand");
while($row=mysql_fetch_array($result)){
echo $row['anzahl'];
}


sowas in der art :P