how do I limit a period of time [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
What i want to do is to limit a user to deposit/withdraw money in the account only 5 times a week , and after the 5 times user must wait next week to be able to deposit again.
I have a table named depuser with the following rows : uid(userid), date(date of dep/witdraw), type(deposit/witdraw) and the amount. thanks in advance

This query will count the # of deposits recorded in the last 7 days, based on your table structure:
SELECT COUNT(uid) AS total_deposits FROM depuser
WHERE `type` LIKE 'deposit' AND
DATE(`date`) <= NOW() AND
DATE(`date`) >= DATE_SUB( NOW(), INTERVAL 7 DAY)`
From here you can compare the total_deposits value returned and make logic decisions.

Related

MySQL: Delete rows that contain a specific parameter and are older then a day [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm creating a login system for my website, with mysql. It works on a subscription based system. How would I remove all rows with the parameter "premium" equal to "1 DAY", if it's older then a day. I'm trying to run a command like this, in a cron job, that runs once a day. I would duplicate this for rows that have the parameter "premium" = "1 WEEK", etc.
Thanks,
It would be something like:
delete t from loginsystem t
where premium = '1 DAY' and created_at < now() - interval 1 day;

The best way to count visits in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have got the mysql table which includes data about users who visited my web service (IP address, date). The one IP address can be logged in my database only once per day.
What is the best way to create the table contains visits from last month? I want something like:
30.10.2016 | 1457
31.10.2016 | 1604
01.11.2016 | 1590
etc
Sorry for English and maybe the very simple question, first time on stack :)
use this sql code to create a table for last month visitor count.
CREATE TABLE last_mon_visit AS
SELECT DISTINCT date, COUNT(ip_address)
FROM visit
WHERE YEAR(date) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
AND MONTH(date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
GROUP BY date
i would suggest to create view instead of table.

Add a mysql subquery to select data from yesterday [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've a delivery system with the following mysql SELECT:
SELECT tb_pedido.*,tb_usuarios.nome,tb_usuarios.email,tb_usuarios.cpfcnpj, DATE_FORMAT(data_hora, '%Y-%m-%d') FROM tb_pedido,tb_usuarios where tb_pedido.id_usuario=tb_usuarios.id_usuario and (status=2 OR status=4) and DATE(data_hora) = CURDATE() order by id_pedido desc
It selects the orders form today with a specific status. What I want to do is to add a sub query to return all results from yesterday with status 8.
I guess the following subquery would work but I don't know how to add it to the current query:
DATE_ADD(DATE(data_hora), INTERVAL -1 day) AND status=8
Anyone please?
Perhaps something like:
SELECT tb_pedido.*,tb_usuarios.nome,tb_usuarios.email,tb_usuarios.cpfcnpj, DATE_FORMAT(data_hora, '%Y-%m-%d')
FROM tb_pedido,tb_usuarios
WHERE
(tb_pedido.id_usuario=tb_usuarios.id_usuario
and (status=2 OR status=4)
and DATE(data_hora) = CURDATE())
OR
(DATE(data_hora) = DATEADD(day, -1, convert(date, GETDATE()))
and status=8)
order by id_pedido desc

Displaying record between two dates [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to display a database record between two date ranges using PHP-mysql.
I am working on a project in which employees payment record is saved in a table. I want to see what amount has been paid between two dates selected through date-picker.
Try this:
SELECT amount FROM mytable WHERE created_at BETWEEN '2011-12-01' AND '2011-12-07';
Assuming mytable to be the table name, created_at to be the date field and amount to be the amount field.
Hope this helps.
Peace! xD
SELECT amount FROM mytable
WHERE
created_at >= '2011-12-01'
AND
created_at <= '2011-12-07';
If you need the sum of the salary between two dates you can do somethig like:
SELECT sum(salary) as total FROM table_name
WHERE job_date BETWEEN 'dd-mm-yyyy' AND 'dd-mm-yyyy';

Fetch mysql records where id is 0,10,20,30, etc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have about 30 000 records in database, and I must create 10 cron jobs for these:
job 1 fetches records where column `id` is 0,10,20,30, etc.
job 2 fetches records where column `id` is 1,11,21,31, etc.
and so forth.
How can I approach this?
Use the modulo operator
select * from your_table
where id % 10 = 1
to get 1,11,21,31,... and so on. And
where id % 10 = 2
for 2,12,22,32,....

Categories