I'm having a hard time. I'm creating a PHP referral system and I'm having a hard time listing clients and how many appointments they've made. The system has two tables, the table 'clients' which is where the data of the same is next to the code of indication of it automatically generated, and the table 'indicated' where it is the id of the client that just registered and the the code of the person who indicated it. Now I'm not sure what logic to use to make the listing of the client that has the most indicated.
Itried,butitstilldidnotwork.
<?php$PDO=conectar();$sql="SELECT * FROM clientes,indicados WHERE cod_cli=codcli_indic ORDER BY id_cli ASC";
$stmt = $PDO->prepare($sql);
$stmt->execute();
while($resultado = $stmt->fetchAll(PDO::FETCH_ASSOC)){
foreach($resultado as $user){
$qtd = count($user['codcli_indic']);
echo "
<tr>
<td>".$user['id_cli']."</td>
<td>".$user['nome_cli']."</td>
<td>".$user['loja_cli']."</td>
<td>".$qtd."</td>
</tr>
";}
}
?>
Mauricioindicated2people,thenthereshouldappear2inMauritiusandnotappeartwiceMauriciointhetable.
Well,I'vetrieddifferentwaysandI'vegotasatisfactoryresult.I'llleavethecodehereifanyonehasthesamedifficulty.
<?php$PDO=conectar();$sql="SELECT *, count(*) as count FROM clientes,indicados WHERE cod_cli=codcli_indic GROUP BY codcli_indic";
$stmt = $PDO->prepare($sql);
$stmt->execute();
$resultado = $stmt->fetchAll(PDO::FETCH_ASSOC);
//$qtd = count($resultado);
foreach($resultado as $user){
if ($user['cod_cli'] == $user['codcli_indic']){
$qtd = count($user['id_indic']);
}
echo "
<tr>
<td>".$user['id_cli']."</td>
<td>".$user['nome_cli']."</td>
<td>".$user['loja_cli']."</td>
<td>".$user['count']."</td>
</tr>
";
}
?>