Jump to content

count & show amount of records of a mysql table via php


gf05856

Recommended Posts

Dear,

I am looking for a php script that gives me the following output based on the amount of records in a particular mysql table:

Fixed output table with 2 columns, 1 column with the numbers 2, 4, 8, 16, 32 .... 1.073.741.824 and a second column that should be filled out with a color based on the amount of records in the mysql table ...

Like you see below there are 7 records in the database ( the | should be replaced by a color).  If you have any ideas on how to visualise this in a better way, then please be my guest! Also the total amount should be show as an amount like .... Total users: 123456

I probably should also consider the fact that when I have 10.000 hits a day on this site that this script is not run 10.000 times back and forward to the database ... but once a day ... and stored.

records    column to fill up

2            |||||||||||||||
4            |||||||||||||||
8            |||||||||||||
16
32
64
128
256
512
1.024
2.048
4.096
8.192
........
Link to comment
Share on other sites

[code]<?php
$query = "SELECT COUNT(*) FROM table";

$result = mysql_query($query) or die(mysql_error());
$count = mysql_result($result, 0);

echo '
<table border="1">
<tr>
<th>Number</th>
<th>&nbsp;</th>
</tr>';
for ($i = 1; $i <= 10; $i++) {
$n = pow(2, $i);

echo '
<tr>
<td>' . $n . '</td>';

if ($count >= $n) {
echo '
<td style="background-color: red;">&nbsp;</td>';
} else {
echo '
<td>&nbsp;</td>';
}

echo '
</tr>';
}

echo '
</table>';
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.