Chip, a couple ideas

1. why not display the select list something like this
<select name="month">
<option value="00">Please Select</option>
<option value="01">January</option>
<option value="02">February</option>
...
</select>

That way the user sees the names of the months, but your database gets sent
nice, easy-to-deal-with numbers?

2. What didn't work with your monthname=>number assignment routine? you
should be able to make a function to do it, something like;

function month_name_to_number($name) {
        switch ($name) {
                case "Jan" :
                        return 1;
                        break;
                case "Feb" :
                        return 2;
                ...
                default :
                        return false;
        }
}

Using this, if the functions returns false, then they haven't selected a
valid name, otherwise it will return a number from 1-12, indicating the
month.

PS - none of that code is tested, but it should work if you finish it off :)

HTH

Beau

// -----Original Message-----
// From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
// Sent: Wednesday, 17 July 2002 5:20 AM
// To: PHP_DB
// Subject: [PHP-DB] change data before its sent to db?
// 
// 
// I have a form with a select box of the 12 months + one for 
// none. It (and
// more) are sent to a mysql
// database. On another web page a list is displayed and can be 
// sorted by
// date, but of course
// the month names are not alphabetical. I tried to assign each month a
// number, 01,02,03, etc in a
// if-elseif statement, then send it to the database but that 
// wouldn't work.
// 
// if ($month == 'jan') { $month = '01';}
// elseif ($month == 'feb') {$month = '02'};
// 
// etc, so I can then sort numerically, and it will display in 
// the correct
// order on the web page.
// I have tried various versions of the above but it will not work.
// I know I could use numbers instead of names for the months - 
// but for this
// application that
// would not be appropriate.
// 
// The sort code ---
// 
//                     if ($orderby == 'month_num'):
//                     $sql = "select * from releases order by 'month'";
//                     elseif ($orderby == 'month_num2'):
//                     $sql = "select * from releases order by 
// 'month' desc";
// 
// The html select ----
// 
// <td valign="bottom">Month:<br />
// <select name="month">
// <option value="000">None
// <option value="Jan">Jan
// <option value="Feb">Feb
// etc
// </select>
// 
// --
// Chip Wiegand
// Computer Services
// Simrad, Inc
// www.simradusa.com
// [EMAIL PROTECTED]
// 
// "There is no reason anyone would want a computer in their home."
//      --Ken Olson, president, chairman and founder of Digital 
// Equipment
// Corporation, 1977
//  (They why do I have 9? Somebody help me!)
// 
// 
// -- 
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, visit: http://www.php.net/unsub.php
// 

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

Reply via email to