PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Newbie question re ORDER
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Newbie question re ORDER

Réponse
 
LinkBack Outils de la discussion
Vieux 01/04/2008, 13h28   #1
Lanse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Newbie question re ORDER

Hi all, I'm not a programmer AT ALL, but I've managed to set up a
website that uses PHP to query a MySQL database for a very basic
output of data. My apologies in advance for any use of incorrect
terminology!

The one thing I still haven't managed is to sort the resulting array
according to a predefined list. I have two fields I'd like to sort
on, "month_in" (a text field) and "day_in" (number field). I'd like
to sort by month (as seen below), and then by day. The example below
is my attempt at the solution,based on a Google search for an answer,
but it's obviously not working. Any would be GREATLY
appreciated!

Lanse

$the_query =
'SELECT * FROM `requests`
ORDER BY find_in_set(month_in,
'May','June','July','August','September'), `day_in` ASC;
$results = mysql_query($the_query, $dbh);
  Réponse avec citation
Vieux 01/04/2008, 14h42   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

Lanse wrote:
> Hi all, I'm not a programmer AT ALL, but I've managed to set up a
> website that uses PHP to query a MySQL database for a very basic
> output of data. My apologies in advance for any use of incorrect
> terminology!
>
> The one thing I still haven't managed is to sort the resulting array
> according to a predefined list. I have two fields I'd like to sort
> on, "month_in" (a text field) and "day_in" (number field). I'd like
> to sort by month (as seen below), and then by day. The example below
> is my attempt at the solution,based on a Google search for an answer,
> but it's obviously not working. Any would be GREATLY
> appreciated!
>
> Lanse
>
> $the_query =
> 'SELECT * FROM `requests`
> ORDER BY find_in_set(month_in,
> 'May','June','July','August','September'), `day_in` ASC;
> $results = mysql_query($the_query, $dbh);
>


I would think you would be better off having a DATE column and just sort
by that column.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 01/04/2008, 18h19   #3
Lanse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Apr 1, 9:42am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Lanse wrote:
> > Hi all, I'm not a programmer AT ALL, but I've managed to set up a
> > website that uses PHP to query a MySQL database for a very basic
> > output of data. My apologies in advance for any use of incorrect
> > terminology!

>
> > The one thing I still haven't managed is to sort the resulting array
> > according to a predefined list. I have two fields I'd like to sort
> > on, "month_in" (a text field) and "day_in" (number field). I'd like
> > to sort by month (as seen below), and then by day. The example below
> > is my attempt at the solution,based on a Google search for an answer,
> > but it's obviously not working. Any would be GREATLY
> > appreciated!

>
> > Lanse

>
> > $the_query =
> > 'SELECT * FROM `requests`
> > ORDER BY find_in_set(month_in,
> > 'May','June','July','August','September'), `day_in` ASC;
> > $results = mysql_query($the_query, $dbh);

>
> I would think you would be better off having a DATE column and just sort
> by that column.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Yes, but my html form just has a month input field and a day input
field... it's for selecting from a small, preset group of dates...
  Réponse avec citation
Vieux 01/04/2008, 19h10   #4
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
> On Apr 1, 9:42am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> Lanse wrote:
>> > Hi all, I'm not a programmer AT ALL, but I've managed to set up a
>> > website that uses PHP to query a MySQL database for a very basic
>> > output of data. My apologies in advance for any use of incorrect
>> > terminology!

>>
>> > The one thing I still haven't managed is to sort the resulting array
>> > according to a predefined list. I have two fields I'd like to sort
>> > on, "month_in" (a text field) and "day_in" (number field). I'd like
>> > to sort by month (as seen below), and then by day. The example below
>> > is my attempt at the solution,based on a Google search for an answer,
>> > but it's obviously not working. Any would be GREATLY
>> > appreciated!

>>
>> > Lanse

>>
>> > $the_query =
>> > 'SELECT * FROM `requests`
>> > ORDER BY find_in_set(month_in,
>> > 'May','June','July','August','September'), `day_in` ASC;
>> > $results = mysql_query($the_query, $dbh);

>>
>> I would think you would be better off having a DATE column and just sort
>> by that column.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================

>
> Yes, but my html form just has a month input field and a day input
> field... it's for selecting from a small, preset group of dates...


Months still got numbers, even if you're starting at 5 instead of 1.

Let's back up a bit. What problem are you trying to solve? Do you only
want to see stuff with dates five months out? Or in a certain range?

--
Usenet should require licenses; licenses that can be revoked.
-- Abigail
  Réponse avec citation
Vieux 01/04/2008, 20h16   #5
Lanse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Apr 1, 2:10pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
> > On Apr 1, 9:42am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> Lanse wrote:
> >> > Hi all, I'm not a programmer AT ALL, but I've managed to set up a
> >> > website that uses PHP to query a MySQL database for a very basic
> >> > output of data. My apologies in advance for any use of incorrect
> >> > terminology!

>
> >> > The one thing I still haven't managed is to sort the resulting array
> >> > according to a predefined list. I have two fields I'd like to sort
> >> > on, "month_in" (a text field) and "day_in" (number field). I'd like
> >> > to sort by month (as seen below), and then by day. The example below
> >> > is my attempt at the solution,based on a Google search for an answer,
> >> > but it's obviously not working. Any would be GREATLY
> >> > appreciated!

>
> >> > Lanse

>
> >> > $the_query =
> >> > 'SELECT * FROM `requests`
> >> > ORDER BY find_in_set(month_in,
> >> > 'May','June','July','August','September'), `day_in` ASC;
> >> > $results = mysql_query($the_query, $dbh);

>
> >> I would think you would be better off having a DATE column and just sort
> >> by that column.

>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================

>
> > Yes, but my html form just has a month input field and a day input
> > field... it's for selecting from a small, preset group of dates...

>
> Months still got numbers, even if you're starting at 5 instead of 1.
>
> Let's back up a bit. What problem are you trying to solve? Do you only
> want to see stuff with dates five months out? Or in a certain range?
>
> --
> Usenet should require licenses; licenses that can be revoked.
> -- Abigail


Sorry for not being very clear...
The webpage form is for submitting reservations for a small campsite,
only available May to September. I made the Month field 'user-
friendly' by using month names instead of numbers... therefore my
dilemma. I can change the page to use numbers... I just hoped there'd
be a simple MySQL way of re-ordering based on a fixed list of values
(like "May, June, July, August, September"). The database is cleared
each year, so there's no need for a 'year' value.

TIA, Lanse
  Réponse avec citation
Vieux 01/04/2008, 21h10   #6
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

Lanse wrote:
> On Apr 1, 2:10 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
>> > On Apr 1, 9:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> >> Lanse wrote:
>> >> > Hi all, I'm not a programmer AT ALL, but I've managed to set up
>> >> > a website that uses PHP to query a MySQL database for a very
>> >> > basic output of data. My apologies in advance for any use of
>> >> > incorrect terminology!

>>
>> >> > The one thing I still haven't managed is to sort the resulting
>> >> > array according to a predefined list. I have two fields I'd
>> >> > like to sort on, "month_in" (a text field) and "day_in" (number
>> >> > field). I'd like to sort by month (as seen below), and then by
>> >> > day. The example below is my attempt at the solution,based on a
>> >> > Google search for an answer, but it's obviously not working.
>> >> > Any would be GREATLY appreciated!

>>
>> >> > Lanse

>>
>> >> > $the_query =
>> >> > 'SELECT * FROM `requests`
>> >> > ORDER BY find_in_set(month_in,
>> >> > 'May','June','July','August','September'), `day_in` ASC;
>> >> > $results = mysql_query($the_query, $dbh);

>>
>> >> I would think you would be better off having a DATE column and
>> >> just sort by that column.

>>
>> >> --
>> >> ==================
>> >> Remove the "x" from my email address
>> >> Jerry Stuckle
>> >> JDS Computer Training Corp.
>> >> jstuck...@attglobal.net
>> >> ==================

>>
>> > Yes, but my html form just has a month input field and a day input
>> > field... it's for selecting from a small, preset group of dates...

>>
>> Months still got numbers, even if you're starting at 5 instead of 1.
>>
>> Let's back up a bit. What problem are you trying to solve? Do you
>> only want to see stuff with dates five months out? Or in a certain
>> range?
>>
>> --
>> Usenet should require licenses; licenses that can be revoked.
>> -- Abigail

>
> Sorry for not being very clear...
> The webpage form is for submitting reservations for a small campsite,
> only available May to September. I made the Month field 'user-
> friendly' by using month names instead of numbers... therefore my
> dilemma. I can change the page to use numbers... I just hoped there'd
> be a simple MySQL way of re-ordering based on a fixed list of values
> (like "May, June, July, August, September"). The database is cleared
> each year, so there's no need for a 'year' value.
>
> TIA, Lanse


Store the months as numbers but display as words (using a Select box for
instance)


  Réponse avec citation
Vieux 01/04/2008, 22h08   #7
Lanse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Apr 1, 4:10pm, "Paul Lautman" <paul.laut...@btinternet.com> wrote:
> Lanse wrote:
> > On Apr 1, 2:10 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> >> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
> >> > On Apr 1, 9:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> >> Lanse wrote:
> >> >> > Hi all, I'm not a programmer AT ALL, but I've managed to set up
> >> >> > a website that uses PHP to query a MySQL database for a very
> >> >> > basic output of data. My apologies in advance for any use of
> >> >> > incorrect terminology!

>
> >> >> > The one thing I still haven't managed is to sort the resulting
> >> >> > array according to a predefined list. I have two fields I'd
> >> >> > like to sort on, "month_in" (a text field) and "day_in" (number
> >> >> > field). I'd like to sort by month (as seen below), and then by
> >> >> > day. The example below is my attempt at the solution,based on a
> >> >> > Google search for an answer, but it's obviously not working.
> >> >> > Any would be GREATLY appreciated!

>
> >> >> > Lanse

>
> >> >> > $the_query =
> >> >> > 'SELECT * FROM `requests`
> >> >> > ORDER BY find_in_set(month_in,
> >> >> > 'May','June','July','August','September'), `day_in` ASC;
> >> >> > $results = mysql_query($the_query, $dbh);

>
> >> >> I would think you would be better off having a DATE column and
> >> >> just sort by that column.

>
> >> >> --
> >> >> ==================
> >> >> Remove the "x" from my email address
> >> >> Jerry Stuckle
> >> >> JDS Computer Training Corp.
> >> >> jstuck...@attglobal.net
> >> >> ==================

>
> >> > Yes, but my html form just has a month input field and a day input
> >> > field... it's for selecting from a small, preset group of dates...

>
> >> Months still got numbers, even if you're starting at 5 instead of 1.

>
> >> Let's back up a bit. What problem are you trying to solve? Do you
> >> only want to see stuff with dates five months out? Or in a certain
> >> range?

>
> >> --
> >> Usenet should require licenses; licenses that can be revoked.
> >> -- Abigail

>
> > Sorry for not being very clear...
> > The webpage form is for submitting reservations for a small campsite,
> > only available May to September. I made the Month field 'user-
> > friendly' by using month names instead of numbers... therefore my
> > dilemma. I can change the page to use numbers... I just hoped there'd
> > be a simple MySQL way of re-ordering based on a fixed list of values
> > (like "May, June, July, August, September"). The database is cleared
> > each year, so there's no need for a 'year' value.

>
> > TIA, Lanse

>
> Store the months as numbers but display as words (using a Select box for
> instance)


OK, I understand how to do the html for the Submit side of things,
where the displayed info is text, and the submitted value is a
number. But then I'm displaying the query results from the
database... so I convert the numbers back to the text format? My
skills are very meager there...

Lanse
  Réponse avec citation
Vieux 01/04/2008, 22h12   #8
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

>Sorry for not being very clear...
>The webpage form is for submitting reservations for a small campsite,
>only available May to September. I made the Month field 'user-
>friendly' by using month names instead of numbers... therefore my


If you are using HTML "SELECT", you can present user-friendly choices
on the page (month names in the language of the user), *AND* give
"machine-friendly" values (month numbers) back to the web server.

>dilemma. I can change the page to use numbers... I just hoped there'd
>be a simple MySQL way of re-ordering based on a fixed list of values
>(like "May, June, July, August, September"). The database is cleared
>each year, so there's no need for a 'year' value.


I recommend you put the month, day, and current year in a DATE
field. Then you can order by it, and do other stuff like day-of-the-week
calculations easily, and use GROUP BY to determine how many
reservations there are for a given day, to see if you have any slots
available. If you need to present a date to the user, in MySQL
there's date_format(), and a bunch of functions in script languages
like PHP or Perl. I recommend displaying the day of the week, too,
which may make users think twice if they are making a reservation
looking at a calendar for the wrong month.

It's impossible for someone to make a reservation in October for
next May? Perhaps always using the current year needs to be examined
closer.


  Réponse avec citation
Vieux 01/04/2008, 22h24   #9
Peter H. Coffin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Tue, 1 Apr 2008 12:16:28 -0700 (PDT), Lanse wrote:
> On Apr 1, 2:10pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
>> > On Apr 1, 9:42am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> >> Lanse wrote:

[...]
>> >> > $the_query =
>> >> > 'SELECT * FROM `requests`
>> >> > ORDER BY find_in_set(month_in,
>> >> > 'May','June','July','August','September'), `day_in` ASC;
>> >> > $results = mysql_query($the_query, $dbh);

>>
>> >> I would think you would be better off having a DATE column and just sort
>> >> by that column.

>>
>> >> --
>> >> ==================
>> >> Remove the "x" from my email address
>> >> Jerry Stuckle
>> >> JDS Computer Training Corp.
>> >> jstuck...@attglobal.net
>> >> ==================

>>
>> > Yes, but my html form just has a month input field and a day input
>> > field... it's for selecting from a small, preset group of dates...

>>
>> Months still got numbers, even if you're starting at 5 instead of 1.
>>
>> Let's back up a bit. What problem are you trying to solve? Do you only
>> want to see stuff with dates five months out? Or in a certain range?

>
> Sorry for not being very clear...
> The webpage form is for submitting reservations for a small campsite,
> only available May to September. I made the Month field 'user-
> friendly' by using month names instead of numbers... therefore my
> dilemma. I can change the page to use numbers... I just hoped there'd
> be a simple MySQL way of re-ordering based on a fixed list of values
> (like "May, June, July, August, September"). The database is cleared
> each year, so there's no need for a 'year' value.


Being clear innit really the issue. The explanation was clear, just ...
kind of asking too specific a question.

There's two ways to attack this issue, one a programming one and the
other a database one, both center on the idea that months have both
names and ordinal numbers. The programming one is a little easier for most
folks to grasp, and that is that you stuff the numbers for the month
into the database and when you're dealing with the user, you look at the
number of the month and print the appropriate name

if ($mysq_result['month'] == 5) { print "May" }
elseif($mysq_result['month'] == 6) { print "June" }
elseif($mysq_result['month'] == 7) { print "July" }
elseif($mysq_result['month'] == 8) { print "August" }
elseif($mysq_result['month'] == 9) { print "September" }
else print "Smarch";

A pure database way of dealing with it would be to have a table with
columns for month number and month name, and make your query look
something like

SELECT name, month_name, day_in from `requests` JOIN `months`
on `requests`.month_in = month_number
ORDER BY month_in, day_in

The nice thing then is that whenever the names of the months change, you
don't have to change the program. This may not seem very useful for
month names, but just wait until you start fussing with things that DO
change, like the designation of campsites or something. ("Hey, lets name
all the sites after trees!" Update your site_number,site_name table and
it's all done.)

--
87. My vats of hazardous chemicals will be covered when not in use. Also, I
will not construct walkways above them.
--Peter Anspach's list of things to do as an Evil Overlord
  Réponse avec citation
Vieux 02/04/2008, 01h05   #10
Lanse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On Apr 1, 5:24pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On Tue, 1 Apr 2008 12:16:28 -0700 (PDT), Lanse wrote:
> > On Apr 1, 2:10pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> >> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
> >> > On Apr 1, 9:42am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> >> Lanse wrote:

> [...]
> >> >> > $the_query =
> >> >> > 'SELECT * FROM `requests`
> >> >> > ORDER BY find_in_set(month_in,
> >> >> > 'May','June','July','August','September'), `day_in` ASC;
> >> >> > $results = mysql_query($the_query, $dbh);

>
> >> >> I would think you would be better off having a DATE column and just sort
> >> >> by that column.

>
> >> >> --
> >> >> ==================
> >> >> Remove the "x" from my email address
> >> >> Jerry Stuckle
> >> >> JDS Computer Training Corp.
> >> >> jstuck...@attglobal.net
> >> >> ==================

>
> >> > Yes, but my html form just has a month input field and a day input
> >> > field... it's for selecting from a small, preset group of dates...

>
> >> Months still got numbers, even if you're starting at 5 instead of 1.

>
> >> Let's back up a bit. What problem are you trying to solve? Do you only
> >> want to see stuff with dates five months out? Or in a certain range?

>
> > Sorry for not being very clear...
> > The webpage form is for submitting reservations for a small campsite,
> > only available May to September. I made the Month field 'user-
> > friendly' by using month names instead of numbers... therefore my
> > dilemma. I can change the page to use numbers... I just hoped there'd
> > be a simple MySQL way of re-ordering based on a fixed list of values
> > (like "May, June, July, August, September"). The database is cleared
> > each year, so there's no need for a 'year' value.

>
> Being clear innit really the issue. The explanation was clear, just ...
> kind of asking too specific a question.
>
> There's two ways to attack this issue, one a programming one and the
> other a database one, both center on the idea that months have both
> names and ordinal numbers. The programming one is a little easier for most
> folks to grasp, and that is that you stuff the numbers for the month
> into the database and when you're dealing with the user, you look at the
> number of the month and print the appropriate name
>
> if ($mysq_result['month'] == 5) { print "May" }
> elseif($mysq_result['month'] == 6) { print "June" }
> elseif($mysq_result['month'] == 7) { print "July" }
> elseif($mysq_result['month'] == 8) { print "August" }
> elseif($mysq_result['month'] == 9) { print "September" }
> else print "Smarch";
>
> A pure database way of dealing with it would be to have a table with
> columns for month number and month name, and make your query look
> something like
>
> SELECT name, month_name, day_in from `requests` JOIN `months`
> on `requests`.month_in = month_number
> ORDER BY month_in, day_in
>
> The nice thing then is that whenever the names of the months change, you
> don't have to change the program. This may not seem very useful for
> month names, but just wait until you start fussing with things that DO
> change, like the designation of campsites or something. ("Hey, lets name
> all the sites after trees!" Update your site_number,site_name table and
> it's all done.)
>
> --
> 87. My vats of hazardous chemicals will be covered when not in use. Also, I
> will not construct walkways above them.
> --Peter Anspach's list of things to do as an Evil Overlord


You guys are great! Thanks so much for the kind assistance. I think
I have enough knowledge now to get it done. And who knows, I may
learn a little more along the way.

thanks again,
Lanse
  Réponse avec citation
Vieux 02/04/2008, 03h24   #11
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

Lanse wrote:
> On Apr 1, 2:10 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
>>> On Apr 1, 9:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>> Lanse wrote:
>>>>> Hi all, I'm not a programmer AT ALL, but I've managed to set up a
>>>>> website that uses PHP to query a MySQL database for a very basic
>>>>> output of data. My apologies in advance for any use of incorrect
>>>>> terminology!
>>>>> The one thing I still haven't managed is to sort the resulting array
>>>>> according to a predefined list. I have two fields I'd like to sort
>>>>> on, "month_in" (a text field) and "day_in" (number field). I'd like
>>>>> to sort by month (as seen below), and then by day. The example below
>>>>> is my attempt at the solution,based on a Google search for an answer,
>>>>> but it's obviously not working. Any would be GREATLY
>>>>> appreciated!
>>>>> Lanse
>>>>> $the_query =
>>>>> 'SELECT * FROM `requests`
>>>>> ORDER BY find_in_set(month_in,
>>>>> 'May','June','July','August','September'), `day_in` ASC;
>>>>> $results = mysql_query($the_query, $dbh);
>>>> I would think you would be better off having a DATE column and just sort
>>>> by that column.
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>> Yes, but my html form just has a month input field and a day input
>>> field... it's for selecting from a small, preset group of dates...

>> Months still got numbers, even if you're starting at 5 instead of 1.
>>
>> Let's back up a bit. What problem are you trying to solve? Do you only
>> want to see stuff with dates five months out? Or in a certain range?
>>
>> --
>> Usenet should require licenses; licenses that can be revoked.
>> -- Abigail

>
> Sorry for not being very clear...
> The webpage form is for submitting reservations for a small campsite,
> only available May to September. I made the Month field 'user-
> friendly' by using month names instead of numbers... therefore my
> dilemma. I can change the page to use numbers... I just hoped there'd
> be a simple MySQL way of re-ordering based on a fixed list of values
> (like "May, June, July, August, September"). The database is cleared
> each year, so there's no need for a 'year' value.
>
> TIA, Lanse
>


Not a problem. Just because you have a month field and a date field on
the form doesn't mean you need to use them in the database.

I virtually always use January-December and a day of month. But when
the form is submitted I convert it to a date for storing in the database.

It makes things a lot easier all around - for instance, reserving a
campsite on June 28th for 7 nights can be handled with standard date
functions in either MySQL or PHP. Your way makes things much harder.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 02/04/2008, 11h58   #12
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Newbie question re ORDER

On 1 Apr, 21:08, Lanse <filema...@jillo.com> wrote:
> On Apr 1, 4:10 pm, "Paul Lautman" <paul.laut...@btinternet.com> wrote:
>
>
>
> > Lanse wrote:
> > > On Apr 1, 2:10 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> > >> On Tue, 1 Apr 2008 10:19:47 -0700 (PDT), Lanse wrote:
> > >> > On Apr 1, 9:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> > >> >> Lanse wrote:
> > >> >> > Hi all, I'm not a programmer AT ALL, but I've managed to set up
> > >> >> > a website that uses PHP to query a MySQL database for a very
> > >> >> > basic output of data. My apologies in advance for any use of
> > >> >> > incorrect terminology!

>
> > >> >> > The one thing I still haven't managed is to sort the resulting
> > >> >> > array according to a predefined list. I have two fields I'd
> > >> >> > like to sort on, "month_in" (a text field) and "day_in" (number
> > >> >> > field). I'd like to sort by month (as seen below), and then by
> > >> >> > day. The example below is my attempt at the solution,based on a
> > >> >> > Google search for an answer, but it's obviously not working.
> > >> >> > Any would be GREATLY appreciated!

>
> > >> >> > Lanse

>
> > >> >> > $the_query =
> > >> >> > 'SELECT * FROM `requests`
> > >> >> > ORDER BY find_in_set(month_in,
> > >> >> > 'May','June','July','August','September'), `day_in` ASC;
> > >> >> > $results = mysql_query($the_query, $dbh);

>
> > >> >> I would think you would be better off having a DATE column and
> > >> >> just sort by that column.

>
> > >> >> --
> > >> >> ==================
> > >> >> Remove the "x" from my email address
> > >> >> Jerry Stuckle
> > >> >> JDS Computer Training Corp.
> > >> >> jstuck...@attglobal.net
> > >> >> ==================

>
> > >> > Yes, but my html form just has a month input field and a day input
> > >> > field... it's for selecting from a small, preset group of dates...

>
> > >> Months still got numbers, even if you're starting at 5 instead of 1.

>
> > >> Let's back up a bit. What problem are you trying to solve? Do you
> > >> only want to see stuff with dates five months out? Or in a certain
> > >> range?

>
> > >> --
> > >> Usenet should require licenses; licenses that can be revoked.
> > >> -- Abigail

>
> > > Sorry for not being very clear...
> > > The webpage form is for submitting reservations for a small campsite,
> > > only available May to September. I made the Month field 'user-
> > > friendly' by using month names instead of numbers... therefore my
> > > dilemma. I can change the page to use numbers... I just hoped there'd
> > > be a simple MySQL way of re-ordering based on a fixed list of values
> > > (like "May, June, July, August, September"). The database is cleared
> > > each year, so there's no need for a 'year' value.

>
> > > TIA, Lanse

>
> > Store the months as numbers but display as words (using a Select box for
> > instance)

>
> OK, I understand how to do the html for the Submit side of things,
> where the displayed info is text, and the submitted value is a
> number. But then I'm displaying the query results from the
> database... so I convert the numbers back to the text format? My
> skills are very meager there...
>
> Lanse


Join to a table containing the the month name and number. Or do as
Jerry suggested and store all the entries as dates in a single (hard
coded) year. Then you can use the FORMAT_DATE and associated date
functions to display in whatever format you like.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h07.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,35314 seconds with 20 queries