Page 1 of 1

help with getting my room count to show correctly!

Posted: Fri 23 Jan 2009 21:02
by Thunder
ok i finaly worked out how to get each selected room but now i have a problem when i try to add the room count to the client it sends the room count as one big number like 1123 and not for each lobby

IE

LOBBY 1 - 3 ROOMS
LOBBY 2 - 1 ROOMS
LOBBY 3 - 50 ROOMS

the way it looks right now is as follows

LOBBY 1 - 3150
LOBBY 2 - 3150
LOBBY 3 - 3150

can anyone help me please thanks P.S my sql is not best so demos would be helpful ...

Code: Select all

 MyQuery.SQL.Text := 'SELECT count(*),groups.name,groups.n FROM groups,rooms WHERE groups.n=rooms.id GROUP BY name';
 MyQuery.Execute;

 while not MyQuery.Eof do begin
   MyQuery.Next;
 end;

   s := s  + 'šRGetGroupsœ'
           + GroupsTable.FieldByName('Name').AsString +'œ' //
           + IntToStr(n) +'œ'
           + GroupsTable.FieldByName('LobbyRate').AsString +'œ'
           + h +'œ'
           + MyQuery.Fields[0].AsString +'œ' // room count
           + k +'œ';
thanks

Need more info...

Posted: Sun 25 Jan 2009 14:42
by Tiko12
Hello Thunder

Without knowing your db schema - it is hard to tell exactly what is wrong...

By looking at the snippet You reveal - it seam like You show the rate - is the rate 3150 ?

regards Tiko

Posted: Sun 25 Jan 2009 18:58
by Thunder
no it shows the correct room count but just in one big line it dont split the count for each lobby

GROUP BY

Posted: Sun 25 Jan 2009 19:32
by Tiko12
- it sounds like You should use GROUP BY - lobbyXX then

Dont know if thats what You are looking for...

Posted: Mon 26 Jan 2009 08:50
by jkuiper

Code: Select all

var query : string;
      S : string;
begin
  with myquery do
  begin
     query := 'SELECT count(*) AS totalrooms, groups.id groups.name, groups.n FROM rooms  GROUP BY groups.id JOIN groups on groups.id = rooms.id'; 
     SQL.text := query;
     Active := true;
     while not eof do
     begin
       S := format('%s'#8'%2d rooms',[fieldbyname('name').AsString, 
                          fieldbyname('totalrooms').AsInteger]);
       showmessage(S);
     end;
  end;
end;
Someting like this