Page 1 of 1
MySQL
Posted: Fri Oct 07, 2011 8:12 am
by jauson
what's the best way to get the total number of data entered for a day? and the total number of data stored in database?.
ex. Table_1 red marker data entered for today
===============
1
2
3
4
5
===============
total number stored is = 5
total number inserted for today is = 1
help will be appreciated.
Re: MySQL
Posted: Fri Oct 07, 2011 8:58 am
by Eric!
Do you have a DATETIME field associated with when this data is stored? You would then just use SELECT data FROM table WHERE added>'2011-10-07 00:00:00'
Assuming your field 'added' is your datetime field when the data was added. Then you can use mysqli_num_rows on your fetched data to see what you've dug up. Or if you don't need to do anything with the data, just do SELECT COUNT(data) FROM table WHERE added>'2011-10-07 00:00:00'
And probably the best way to get the total number of rows is to make SQL do it by: SELECT COUNT(*) FROM table
And the result will be the number of rows in your table.
Re: MySQL
Posted: Sat Oct 08, 2011 12:26 am
by jauson
Line statement.1 Thanks buddy! It works okay now.
<?php
#-- GET connection essentials
$host="Localhost";
$username="root";
$password="root";
$db_name="bbs";
$tbl_name="t_board";
mysql_connect('Localhost','root','root') or die('Unable to connect!'.mysql_error());
mysql_select_db("bbs") or die('Unable to select DB!'.mysql_error());
$query = 'SELECT COUNT(*) FROM `t_board`';
$result = mysql_query($query) or die('Sorry, we could not count the number of results: ' .mysql_error());
$numberofresults = mysql_result($result, 0);
echo $numberofresults ;
?>
=============================================================================================
Line statement 2. I saw this script --> SELECT "COUNT(data) FROM table WHERE added>'2011-10-07 00:00:00'" <-- Questions: Is it automatic the mysql will execute this script every after a day? or you just need to specified the date "2011-10-07 00:00:00'" per day? so the script will execute properly? many thanks!

Re: MySQL
Posted: Sat Oct 08, 2011 2:52 pm
by egg82
Code: Select all
<?php
#-- GET connection essentials
$host="Localhost";
$username="root";
$password="root";
$db_name="bbs";
$link = mysql_connect($host,$username,$password);
if(!$link){
echo("Unable to connect: ".mysql_error());
exit();
}
$connect = mysql_select_db($db_name);
if(!$connect){
echo("Unable to select DB: ".mysql_error());
exit();
}
$result = mysql_query("SELECT * FROM `t_board`;");
if(!$result){
echo("Sorry, we could not count the number of results: ".mysql_error());
exit();
}
echo("Total results: ".mysql_num_rows($result));
mysql_free_result($result);
$result = mysql_query("SELECT * FROM `t_board` WHERE `date`='".date("m/d/Y")."';");
if(!$result){
echo("Sorry, we could not count the number of results: ".mysql_error());
exit();
}
echo("Today's results: ".mysql_num_rows($result));
mysql_free_result($result);
?>