This is a discussion on Newbie question re ORDER within the MySQL forums, part of the Database Server Software category; --> Lanse wrote: > On Apr 1, 2:10 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote: >> On Tue, 1 Apr 2008 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 help 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 ================== |
| ||||
| 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 help 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. |