php mysql car parking query [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Hey i need a bit mysql query help..
i have a table named airport_car_parking with 4 fields
id [int autoincrement primary key]
email [varchar]
departure_date [DATETIME]
arrival_date [DATETIME]
now i have two variables $departure_date [something in datetime format] and $arrival_date [something in datetime format]
I want to write a query in php - mysql that checks whether my booking days belongs into above table booking dates or not...
say if i consider my above table data like below
id | email | departure_date | arrival_date
1 | abc#gmail.com | 2013-12-22 12.15.00 | 2013-12-25 12.15.00
so no one can book a car in those 3 days of dec 2013
i have two variable like
$departure_date= 2013-12-24 12.15.00 and
$arrival_date= 2013-12-26 12.15.00
but a car can not be park in those days because table data shows that in this time already a car is booked... i need a query that checks any booking plot is available or not.
I write a query like below , but its valid only after existing period
$chk_date_sql="select * from airport_car_parking where return_date >= '$deperture_date'";

Your query is referencing return_date, which isn't a column in the airport_car_parking table.
As for the logic of the query, you want to make sure that the $departure_date isn't between any row's departure_date or arrival_date. I would recommend the following query -
$chk_date_sql="SELECT * FROM airport_car_parking WHERE '$departure_date' BETWEEN departure_date AND arrival_date;";
And then that query returns with any rows, that means that the requested time will not work.

Related

How to check overlapping dates between multiple date ranges? [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 2 years ago.
Improve this question
Sorry for my bad english, but I have a problem about check duplicate date.
I have a list date includes from_date and to_date in database and I want check like below:
In database:
from_date | end_date
-------------------------
2020/02/10 | 2020/02/15
-------------------------
2020/01/20 | 2020/01/31
-------------------------
2020/02/16 | NULL
-------------------------
Input:
input['from'] = 2020/01/15;
input['to'] = 2020/01/25;
input['from'] = 2020/01/10;
input['to'] = NULL;
NULL meaning the date unlimited after.
Condition:
Check input[from] and input[to] does not overlap with another range in the database.
in this case:
input is invalid:
because
dates in 2020/01/15 - 2020/01/25 overlap with range 2020/01/20 - 2020/01/31
dates in 2020/01/10 - NULL overlap with range 2020/02/16 - NULL
valid case:
2020/02/01 - 2020/02/09
2020/01/10 - 2020/01/19
You can use the following logic to get rows that have any overlap (other than the endpoints) for the parameters:
select d.*
from dates d
where d.from_date < #to and
(d.to_date > #from or d.to_date is null)

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.

salary incrment of each year from date but some date(year) are not in database [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 8 years ago.
Improve this question
i am working on php mysql HR application and i have a table with some field like date and salary and incremented salary as shown the below screenshot.
i want a list of a record of each year but some year(date) not in a data base how to get that year as shown in 2nd screenshot
Thanks..
You don't want that result.
In the first place, ID = 2 is already in use for the year 2014; assigning 2013 to it is a bad, bad idea. In the second place, it makes no sense to say that the salary for 2013 is 3500, and the increment is 0, when 2013 isn;'t in the database.
If 2013 is supposed to have those values, then put them in the database.
Otherwise, create a table of years (or a table of integers), and include it in your query with an outer join.
create table years (
yr integer primary key
);
insert into years values
(2012), (2013), (2014), (2015), (2016),
(2017), (2018), (2019), (2020), (2021);
Now you can join those two tables with an outer join. The coalesce() expression isn't strictly necessary with an outer join, but I think it expresses the result you want.
select salaries.id, coalesce(salaries.date, years.yr) as date,
salaries.salary, salaries.increment
from years
left join salaries on
salaries.date = years.yr
where years.yr between 2012 and 2015
order by years.yr;

mysql group by only date and count how many results [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a sample table name (info) in mysql database as follows:
id dateAdded
----------------------------
1 2013-12-24 03:03:19
2 2013-12-24 03:04:19
3 2013-12-24 03:06:14
4 2013-12-24 03:07:23
5 2013-12-25 03:04:19
6 2013-12-26 03:02:19
7 2013-12-26 03:03:19
I have another table name (error) as follows:
id date
----------------------------
11 2013-12-24 03:03:19
22 2013-12-24 03:04:19
33 2013-12-25 03:06:14
53 2013-12-25 03:04:19
62 2013-12-26 03:02:19
I want to COUNT how many ids from the two tables (info and error) with the same dates , so the result out will be :
date countinfo counterror
----------------------------------------
2013-12-24 4 2
2013-12-25 1 2
2013-12-26 2 1
Please if you could help me out with the Mysql query
Give this a try, maybe it can be written in a better way but this gives the desired output.
SELECT
DATE(Sub.dateadded) as `Date`,
( SELECT count(id)
FROM test.info
WHERE DATE(info.dateadded)=DATE(Sub.dateAdded)) as `CountInfo`,
( SELECT count(id)
FROM test.`error`
WHERE DATE(`error`.`date`)=DATE(Sub.dateAdded)) as `ErrorInfo`
FROM
(
SELECT `date` as dateadded
from test.`error`
UNION SELECT dateadded
FROM test.info
) Sub
GROUP BY Date(Sub.dateadded)
Notice that my database name used here is test, change that to your database name.
Since the date field is from different tables, you must UNION them in a subquery so that you can get the relevant dates. Then from there a simple subquery in the select is executed with the dateparameter.
In the future, try to name your tables with names that is not a datatype or function name etc, then the ` is not needed to wrap the database,table,column names
EDIT
If you want specific dates, just make use of WHERE.
Add this line before the GROUP BY
WHERE DATE(Sub.dateadded) IN ('2013-12-24','2013-12-25')
If you want between a time span you can do this
WHERE DATE(Sub.dateadded) BETWEEN '2013-12-24' AND '2013-12-30'
This will give the dates available between 24-30 of December.
Try this, please rename the table name that I have provided.
Info : Join both table get the count of distinct Id
select Date(dateadded) as datepart,
count(distinct(infotable.id)) as countInfo,
count(distinct(errortable.id)) as counterror from infotable inner join errortable
on Date(infotable.dateadded)=Date(errortable.date)
group by datepart
Try this for a pure MySQL approach:
SELECT dateAdded, COUNT(*) as count_info FROM info GROUP BY dateAdded;
SELECT date, COUNT(*) as count_error FROM error GROUP BY date;

Counting votes between certain dates [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I've done a system for a client where they can nominate colleagues for doing a great job. Each person has 12 nominations to give annually.
So I've got a database with a table nominations which stores, id, nominator(id), nominated(id), reason and date.
I've also got a table user which stores user data such as, total nominations given, received, id, email etc.
So I'm creating a page from which you can pull reports.
Here you can choose a start date and end date and amount of records you would like.
How would the SQL query look to determine who made the most nominations between the specified dates?
I'm not a SQL guru at all...so any help would be appreciated very much.
After some research I've managed to find out COUNT(*) is the way to go...but don't want to run a query for every user that nominated between the specified dates...and sorting it this way could be a problem.
Please any help would be great.
select nominator, count(*)
from yourTable
where nominatedDate >= '1 Jan 2013' and nominatedDate <= '31 Jan 2013'
group by nominator
When you do aggregation functions (like COUNT. MIN, MAX, AVG) you either need to apply them to every row selected, which will give just one row in the output, or to GROUP BY items you want to make into sub-totals. In this case, for each value of Nominator in the table we get the Nominator value, and the count of rows containing that value.
The Where clause limits the counted rows to those where nominatedDate is in the given range. You can put AND and OR other tests (its already got one and).

Categories