0
I have this script:
<?php
include 'config.php';
if(isset($_POST)){
$user = isset($_POST['user']) ? strip_tags($_POST['user']) : 'HabboColorFS';
$rank = $pdo->query("SELECT * FROM topicos_comentarios WHERE autor='".$user."'")->rowCount();
$usuario = $pdo->prepare("SELECT * FROM usuarios WHERE usuario='".$user."'");
$usuario->execute();
while($ver = $usuario->fetch(PDO::FETCH_ASSOC)){
?>
<?php print $usuario->rowCount(); ?>
<div class="image" style="background-image: url('<?php echo $cx_uploads; ?>/<?php echo $ver['avatar']; ?>')">
<div class="comments"><i class="fa fa-comments" aria-hidden="true"></i> <?php echo $rank; ?></div>
<div class="comments"><i class="fa fa-commenting" aria-hidden="true"></i> 123</div>
<div class="base">
<div class="avatar" style="background-image: url('https://www.habbo.com.br/habbo-imaging/avatarimage?&user=<?php echo $ver['usuario']; ?>&action=std&direction=3&head_direction=3&img_format=png&gesture=std&headonly=0&size=s')"></div>
</div>
</div>
<div class="type day">
<div class="totype"><i class="fa fa-trophy" aria-hidden="true">
</i> RANKING DO DIA</div>
<div class="position">178º</div>
</div>
<div class="type all">
<div class="totype"><i class="fa fa-trophy" aria-hidden="true">
</i> RANKING GERAL</div>
<div class="position">178º</div>
</div>
<?php } } ?>
I am trying to make an if that when $user->rowCount() is 0 it display an error message "echo "no user found"".
I put print $usuario->rowCount(); and I tried with echo tbm, I already did if that way, but when I do a purposeful search to empty it does not display 0.
How can I solve?
Have you tried putting the
rowCount
outside thewhile
in which you do thefetch
?– Woss
Wow, it worked out! kkkk. Thanks, can you explain to me why it only works out?
– Paulo Sérgio Filho
Why the method
fetch
will returnfalse
when there are no records, in which case thewhile
.– Woss
Understood! Thank you very much.
– Paulo Sérgio Filho