SELECT

SELECT

am 17.10.2011 19:38:22 von ron.piggott

------=_NextPart_000_0080_01CC8CD2.0A121600
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


I need help creating a mySQL query that will select the correct =
introduction message for a website I am making. The way I have designed =
the table I canâ€=99t wrap my mind around the SELECT query that will =
deal with the day # of the month. =20

The part of the SELECT syntax I am struggling with is when the =
introduction message is to change mid month. The reason I am struggling =
with this is because I havenâ€=99t used â€=98DATEâ€=99 for =
the column type. The reason I didnâ€=99t use â€=98DATEâ€=99 =
is because the same message will be displayed year after year, depending =
on the date range. =20

What I am storing in the table is the start month # (1 to 12) and day # =
(1 to 31) and then the finishing month # (1 to 12) and the finishing day =
# (1 to 31)

Table structure for table `introduction_messages`
--

CREATE TABLE IF NOT EXISTS `introduction_messages` (
`reference` int(2) NOT NULL AUTO_INCREMENT,
`start_month` int(2) NOT NULL,
`start_day` int(2) NOT NULL,
`end_month` int(2) NOT NULL,
`end_day` int(2) NOT NULL,
`theme` varchar(100) NOT NULL,
`message` longtext NOT NULL,
PRIMARY KEY (`reference`)
) ENGINE=3DMyISAM DEFAULT CHARSET=3Dlatin1 AUTO_INCREMENT=3D8 ;

My query so far is:

SELECT * FROM `introduction_messages` WHERE 11 BETWEEN `start_month` AND =
`end_month`

11 is for November. 2 rows have been selected:

Row #1:
`start_month` 9
`start_day` 16
`end_month` 11
`end_day` 15

Row #2:
`start_month` 11
`start_day` 16
`end_month` 12
`end_day` 10

How do I modify the query to incorporate the day #?

Ron




www.TheVerseOfTheDay.info=20

------=_NextPart_000_0080_01CC8CD2.0A121600--

Re: SELECT

am 17.10.2011 19:58:11 von Jim Giner

I would do it this way:

Where
$sel_d = (the day # you want)
$sel_m = (the month # you want)

The "where" clause would be:

Where (start_month => $sel_m and start_day => $sel_d) and
(end_month =< $sel_m and end_day =< $sel_d)

Someone else will probably have something more elegant, but I believe this
will work for you.

Never used the between clause before - have to remember that.



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re: SELECT

am 17.10.2011 20:20:24 von Toby Hart Dyke

Though the operators are >= and <=, not => and =<.

Toby

-----Original Message-----
From: Jim Giner [mailto:jim.giner@albanyhandball.com]
Sent: Monday, October 17, 2011 1:58 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Re: SELECT

I would do it this way:

Where
$sel_d = (the day # you want)
$sel_m = (the month # you want)

The "where" clause would be:

Where (start_month => $sel_m and start_day => $sel_d) and
(end_month =< $sel_m and end_day =< $sel_d)



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: SELECT

am 18.10.2011 03:16:37 von Amit Tandon

RE: SELECT

am 18.10.2011 12:36:15 von M.Ford

Re: SELECT

am 18.10.2011 16:31:20 von Jim Giner