How to query data expiration time in mysql php [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In my Database I have products that i saved with the expiration timestamp in the format eg. 2018-22-08. Please how do I select all products that will expire in less than 4 days.
I have tried
SELECT * FROM table WHERE expiration_timestamp = DATE_ADD(CURDATE(), INTERVAL 4 DAY)

You should use less than operator
SELECT * FROM table WHERE expiration_timestamp < DATE_ADD(CURDATE(), INTERVAL 4 DAY)

Related

foreach loop with if statements [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 days ago.
Improve this question
<?php
$income = array(19500, 22000, 85205, 110000, 26568, 12000, 37500, 50900, 28000, 32430);
$percentage = 0.09;
foreach($income as $integers)
{
echo ("$integers <br/>");
}
if ($integers < 26568);
{
echo "$integers = Pay back £0 per year";
}
?>
outcome below
19500
22000
85205
110000
26568
12000
37500
50900
28000
32430
32430 = Pay back £0 per year
If it is lower than 26568 then next to the number I want it to say "Pay back £0 per year" but if it's more than 26568 I need to calculate 9 percentage and add how much is paid back next to the number. Is this possible?
I tried the above and keep getting the same output, I need to be able to calculate the 9 percent and add this next to the number.

Get all results of 1 year ago and older datetime field [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
I want to check if an membership of an user is created 1 year ago or longer.
I have this now:
SELECT * FROM users WHERE date >= NOW() - INTERVAL 1 YEAR
But i get results of 17-03-2021 in the list, when that is not an year ago.
I want to get all results from the Users when created account one year ago
or longer than.
How i can do that? I googled but i cant find an solution.
Thanks in advance.
SELECT * FROM users WHERE date < NOW() - INTERVAL 1 YEAR
Where date smaller then one year ago, you had greater then.

This code is not decreasing the value by 1 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to update next table named 'book' but this UPDATE code is not working
"UPDATE books SET Quantity=Quantity-1 Where Book_ID='$Book_ID'";
this code should update the books table by decreasing the value of Quantity by 1
You need to decrease from column value, not PHP variable. Remove the dollar sign and quotes, of you have there integers.
UPDATE books SET Quantity = Quantity - 1 Where Book_ID = '$Book_ID'
Don't forget that you are vulnerable to SQL injection in WHERE clause.

php mysql ORDER BY not working ... tried looking at others, they aren't having the same issue [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
please help ... i'm pretty knowledgeable when it comes to php mysql, but for some reason i can't figure this out.
i have this query:
$get_points = "SELECT user_id, accum_points FROM total_points ORDER BY accum_points DESC";
$run_points = mysqli_query($con, $get_points);
while($row_points = mysqli_fetch_array($run_points)) {
other stuff in here
}
and here's what is currently in the db
points_id | user_id | accum_points
_____________________________________
31 12 211.2
32 13 7.4
33 1 10.4
but it spits out it in the order of 7.4, 211.2, 10.4. i don't understand what is going on with this ... i've looked at a lot of the other questions asked about ORDER BY not working ... can anybody help?
thanks!
i made the mistake of making the column a varchar ... so that was stupid of me ... sorry about this guys

delete rows in mysql database if selected time has passed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want to delete rows from the database once a set amount of time has passed and the code I have isn't working and I am not sure where I have gone wrong. I plan to change the amount of time to 1 month but it is currently 1 minute for testing purposes.
require 'core/init.php';
$remOld = "DELETE * FROM `ratings` WHERE `ratedate` < NOW() - INTERVAL 1 MINUTE";
if ($remOld = $db->query($remOld)){
echo ('records removed');
}else{
echo ('didnt remove records');
}
Any pointers would be much appreciated.
Remove * from query and close open bracket in your query.
DELETE FROM `ratings` WHERE `ratedate` < (NOW() - INTERVAL 1 MINUTE)
try like this
$remOld = "DELETE FROM `ratings` WHERE `ratedate` < NOW() - INTERVAL '1 MINUTE'";
if ($remOld = $db->query($remOld)){
echo ('records removed');
}else{
echo ('didnt remove records');
}

Categories