I have a table in MYSQL database with 14586 records.
each record has a row called active with a value of 0.
at some point the value of this active row becomes 1.
what i need to do is to simply display a bootstrap progress bar showing the fields that have the active=1 in the progress bar.
I tried something like this:
PHP:
$result = mysqli_query($db_conx, "SELECT count(*) FROM mytable WHERE active=1");
$row = mysqli_fetch_row($result);
$num = $row[0];
Bootstrap HTML:
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $num; ?>%">
<?php echo $num; ?>%
</div>
</div>
But this is wrong because I get a silly number like this 14586% in the progress bar.
Could someone please advice on this?
any help would be great.
Thanks in advance.
cout(id)orcount(active)instead of selecting all columns withcount(*)to speed up your query.COUNT(*)can sometimes out perform counting a specific column. This allows MySQL to try to select the best indexed column for your query. The other thing to note is if there arenullvalues in the column you select to be counted those values will be ignored. Always test multiple methods of counting rows for your application as what works best for someone else may not work best for you.