0
votes

I have a database and there is an 'users table' in it. In this table, there are columns which contain users information (site, nick, jeton, mail, sifre). I am trying to make a program based on a credit system. Any user runs the program, than, if the users credit is equal to number of sites in listbox (i mean number of lines) the users site will appear in the listbox. Otherwise, it won't appear.

In the database, value in 'credits' column must be equal to number of lines in listbox. For example, if any users credit value is 4 and there are 5 lines in listbox, the users site won't be added to listbox. But if the user's credit value is 5 or higher, his/her site will be added (listed) in the listbox.

uyeler = table

nick = user name column.

site = user site name column.

jeton = user credit column.

mail = user mail column.

sifre = user password column.

I tried these;

MyQuery1.Close;
 MyQuery1.SQL.Text :='SELECT jeton, site FROM uyeler WHERE jeton > 0 ORDER BY site';
  MyQuery1.Open;
  ListBox1.Items.Clear;
  If (MyQuery1.IsEmpty) or (MyQuery1.FieldByName('jeton').AsString > IntToStr(Listbox1.Items.Count)) Then
  Begin
  MessageDlg('warning: you have not credit!', mtWarning,[mbOK],0)
  End
  Else
  Begin
  While not MyQuery1.Eof do
  Begin
  ListBox1.Items.Add(MyQuery1.Fields[1].AsString);
  MyQuery1.Next;
  end;
 MyQuery1.Close;
End;
1
> "if any users credit value is 4 and there are 5 lines in listbox, the users site won't be added to listbox. But if the user's credit value is 4 or lower, his/her site will be added (listed) in the listbox" > This doesn't make sense, you require the outcome to be different for '4 or lower' and '4'.Sertac Akyuz
@SertacAkyuz, Pardon, I have edited now.Ankara
I'm having a hard time understanding, but anyhow, for starters, it looks like you're interested with the credits of a particular user, but your select statement will retrieve all records with jeton > 0. You either need to select the record for that user (where (nick = xyz) and (jeton > 0)), or locate the record of that particular user in the query. I suggest you to attach a DBGrid to your query so that you can be sure that your query is retrieving the records that you intend to. I may be misunderstanding though..Sertac Akyuz

1 Answers

0
votes

If I'm understanding you correctly. There is a listbox of sites. If the user who runs the program has credits which equals the number of lines in a listbox, then that user's site will be added to the listbox. Also I'm working off the assumption that one user can have many sites.

Firstly change your sql query to return the data based on if the user is found. i.e.

Treat the code below as pseudo code!

MyQuery1.SQL.Text :='SELECT jeton, site FROM uyeler WHERE nick =:nick and jeton > 0 ORDER BY site';
MyQuery.Params['nick'] = userName;  //Check syntax as this line is meant as pseudo code

int noOfUserCredits = MyQuery1.FieldByName('jeton');

if (noOfUserCredits >= listBox.lines.Count)
begin
  while not MyQuery1.Eof do
  begin
    ListBox1.Items.Add(MyQuery1.FieldByName('site').AsString);
    MyQuery1.Next;
  end;
end else
if (noOfUserCredits < listBox.lines.Count)
begin
  //Do stuff
end else
if ((noOfUserCredits == 0) or (MyQuery1.IsEmpty))
begin
  MessageDlg('warning: you have not credit!', mtWarning,[mbOK],0);
end;