0
I would like the code to automatically count and show next to the form options, the amount of times the values that are pulled from the database appear in the TABLE clients COLUMN account
Obs: The values of the options are pulled from the TABLE Accounts COLUMN user, and wanted the values pulled that are in the options to be counted in the TABLE clients COLUMN account
wanted to leave so equal in the image:
https://i.stack.Imgur.com/xceBC.png
already this last value is not registered in the table Accounts user column so it does not need to appear in the options nor be counted. https://i.stack.Imgur.com/hB6Jh.png
SELECT account, COUNT(*) FROM clients GROUP BY account
<div class="form-group">
<text class="bold">
Conta *
</text><br>
<select name="conta" class="form-control" required>
<option value="">Selecione a conta</option>
<?php
while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
{
echo "<option value='".$row['usuario']."'>".$row['usuario']."</option>";
}
}
?>
</select>
</div>
and if possible to count and give 6 or more, disable the option (disabled).
perfect! thank you so much for helping! :)
– Felipe S.
Actually that alias you told me about where I put it? because I just changed the $sqldata variable = "SELECT * FROM Accounts"; to what you said $data = "SELECT account, COUNT(0) total FROM clients GROUP BY account"; and instead of pulling the accounts from the Accounts table pulled the accounts from the clients table.
– Felipe S.
You didn’t want to count the amount of accounts in the table
clients
? That it was the select that passedSELECT conta, COUNT(*) FROM clients GROUP BY conta
. If it’s fromaccounts
(if I understood correctly, it would beSELECT usuario, COUNT(*) FROM accounts GROUP BY usuario
. Or you want to pull values fromaccounts
and tell ofclients
? What is the link between the 2 tables?– rbz
is that in the ACCOUNTS table I register the accounts, and in the CLIENTS table I register the customers, and at the time I register the customers I pull the accounts that are available from the ACCOUNTS table, and I can register up to 6 clients for each account, is basically a sharing of accounts, why at the time I am registering the client wanted to see by the options how many are using that account, understand?
– Felipe S.
Now I understand, so you have to make a
JOIN
. And there is no reason you bring the accounts with more than 5, since it will leave disabled, only behind those who still have "space". I won’t be able to do that now, maybe a little later, or tomorrow, and I’ll update my answer to you.– rbz
How’s the client-client relationship? Because this "user" field in "Accounts" is strange, since you link more than one user in an account, right!?
– rbz
Actually the ACCOUNTS table has a user field, and the CLIENTS table has an account field, but the same data is stored, only only with a different name. the values stored in the USER table ACCOUNTS column go to the ACCOUNT column of the CLIENTS table. I think I just put so at the time, for me not to confuse with the name of the person, so I did not put user put account.
– Felipe S.
Try it this way:
SELECT c.codigoconta, (SELECT COUNT(0) FROM accounts WHERE conta = c.id) total FROM clients c
. where iscodigoconta
, is the field of the account that should display, which should beid
probably. Then you have to change$row['conta']
for the correct column name.– rbz
It has a lot of wrong definition, the correct is to restructure this comic first, understand why, then understand the select, then the while.
– rbz
I didn’t understand that last code you passed, I changed it
codigoconta
forconta
but came normal without telling and came (0).– Felipe S.