Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
MONTHLY COUNTER QUESTION (for PHP pro's)
Hi.. i know that many of you know php well, and i need your help, guys.. i need to make a counter, which would nullify on the 00:00:01 of the first day of each month.. so,,, it would count the quantity of occurances of something during a month,, and then simply return to zero with the start of a new month... i am coding in php.. what would you advise?
i am a noob in php, however I can code relatively simple web-applications, so i think technical terms i will understand...
this will be an online book-keeping application for a furniture retailer.,.. I am using php and mysql on apache
hope for your help
thanks in advance
i am a noob in php, however I can code relatively simple web-applications, so i think technical terms i will understand...
this will be an online book-keeping application for a furniture retailer.,.. I am using php and mysql on apache
hope for your help
thanks in advance
0
This discussion has been closed.
Comments
$current_year_month = date('Y-m'); $counter_for[$current_year_month]++;
and chuyskywalker, i did not understand what tried to say there,,, either it is wrong,,, or i am a newb... i do not need increment by one... i need a nullification ,, increment is not big deal,.. i can handle it by mysql,, if any of you guys could write a general algorithm, i would really appreciate it.. thanks
CREATE TABLE `time` ( ... `timestamp` INT(11) NOT NULL, ... );
...and then you would use a basic insert to insert...
INSERT INTO `time` VALUES(..., UNIX_TIMESTAMP(), ...);
...then to find the values of each month, just use this...
<?php $Month = 5; $Year = 2006; $Start = mktime(0, 0, 0, $Month, 1, $Year); if($Month == 12) { $Month2 = 1; $Year ++; } else $Month++; $End = mktime(0, 0, 0, $Month2, 1, $Year)-1; $data = mysql_fetch_assoc(mysql_query("SELECT count(*) as Number FROM `time` WHERE time.timestamp > ".$Start." AND time.timestamp < ".$End.";")); echo 'The Number of views for '.date('F', $Start).' was '.$data['Number']; ?>
...and BOOM, you have it, and it can be calculated for any month
wow, i haven't done something like this for a long time, though it only too me 5 min
function make_id() { global $id; $m=date('m'); $y=date('y'); settype($m, 'integer'); settype($y, 'integer'); $cq=db('SELECT * FROM cur_date LIMIT 1'); $cd=mysql_fetch_assoc($cq); if (($cd['m']==$m)&&($cd['y']==$y)) db('UPDATE cur_date SET d=d+1'); else { if (($cd['m']==12)&&($m==1)) { db('UPDATE cur_date SET d=1, m=1, y=\'' .$y. '\''); } else db('UPDATE cur_date SET d=\'1\', m=\'' .$m. '\''); } $nq=db('SELECT * FROM cur_date LIMIT 1'); $nd=mysql_fetch_assoc($nq); $id=$nd['d']. '_' .$nd['m']. '_' .$nd['y']; return $id; }
am i a newb in php? :P
cur_date
with 3 parameters (columns), which are order (d
), month (m
), and year (y
). And there is only one row of data, which changes just before assigning an id to every next order. So what i did is I made a funciton which checks whether it is the end of the year, if not, it checks whether we are still in the same month, and if yes, it increments the database value ofd
and assigns a new automatically generated id to an order.What is unclear with your code is the mysql queries. I am not very good at mysql syntax, i only know the very basic functions. So this
count(*)
is unfamiliar. I looked it up at the mysql documentation, and it looks quite useful, however i have managed to create id function with the knowledge i have got so far. Thanks anyway.btw, what do you think of my function. Is it decent or lame?
and you function is a bit overload, you've got to find the quickest way to do things
also, UNIX_TIMESTAMP() for mysql is exactly the same as time(), but it allows the database to do it
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
Here is the code I am using to count the discussions. Any help would be appreciated.
$data = mysql_fetch_assoc(mysql_query("SELECT count(*) as Number FROM ".$Context->Configuration['DATABASE_TABLE_PREFIX']."discussion;"));