/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Mysql/php select date but only 1

Hey really quick one.

My form creates bookings, but because they are lots of products and can be booked out on the same date.

What i would like is, if there is a booking on that date, return of them, and continue.

Example:

id — date — product
1 — 2011-6-20 — item1
2 — 2011-6-21 — item1
3 — 2011-6-22 — item2
4 — 2011-6-20 — item3
5 — 2011-6-23 — item3

Any thats the same date marked down as once, like id 1 and 4 since they have the same dates, should only do the next stage once.

[code=php]
$bookQuery = mysql_query(“SELECT DAY(Booking_Date) as ‘d’, MONTH(Booking_Date) as ‘m’, YEAR(Booking_Date) as ‘Y’, id, Booking_Name FROM bookings”);
$num_rows = mysql_num_rows($bookQuery);

$i=0;
while ($row = mysql_fetch_array($bookQuery)) {
$d = $row[‘d’];
$m = $row[‘m’];
$Y = $row[‘Y’];
$booking_id = $row[‘id’];
echo ‘{ title: ‘Booking’, start: new Date(‘.$Y.’, ‘.$m.’, ‘.$d.’), url: ‘index.php?function=viewBooking&day=’.$d.’&month=’.$m.’&year=’.$Y.” }’;
if ($i != $num_rows) { echo ‘,’; }
$i++;
}

[/code]

The output should be the following from the above example:

[code=php]
{ title: ‘Booking’, start: new Date(2011, 06, 20), url: ‘index.php?function=viewBooking&day=20&month=06&year=2011’ },
{ title: ‘Booking’, start: new Date(2011, 06, 21), url: ‘index.php?function=viewBooking&day=21&month=06&year=2011’ },
{ title: ‘Booking’, start: new Date(2011, 06, 22), url: ‘index.php?function=viewBooking&day=22&month=06&year=2011’ },
{ title: ‘Booking’, start: new Date(2011, 06, 23), url: ‘index.php?function=viewBooking&day=22&month=06&year=2011’ }
[/code]

And as you should see it skipped id 4.

Hope i explained ok, as always thanks for any help! ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 19.2011 — Since all you are actually using are the date values from the query, leave out the other columns, then make it distinct:
[code=php]
$query = "
SELECT DISTINCT
DAY(Booking_Date) as d,
MONTH(Booking_Date) as m,
YEAR(Booking_Date) as Y
FROM bookings
ORDER BY Y, m, d
";
[/code]
Copy linkTweet thisAlerts:
@LiL_aaronauthorJun 20.2011 — Thank you mate! Your knowlegde of the force... i mean php is awesome!
×

Success!

Help @LiL_aaron spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...