The objective is to get rid of all the drop-downs and use a function instead of replicating the gory details over and over (there are 12 places this is used) but until I understand this, I can't write the correct function.

Any ideas?

This post has been edited by no2pencil: 19 October 2012 - 08:15 PM
Reason for edit:: Added Code Tags

Replies To: I don't understand the line of code

Re: I don't understand the line of code

Posted 19 October 2012 - 08:30 PM

1. You can just use SELECTED. That's what I prefer, anyways.

2. It looks as if the original programmer was trying to convert the month from it's number format to the spelled equivalent (IE "12" == "December"). Not only is this a bad way of doing things, but it's also very poorly written. This snippet will return the month's name, where $month is the month's number:

date('F', mktime(0, 0, 0, $month));

EDIT:

Oh, it looks like you're trying to make the code smaller... Anyways, you can use this function:

Re: I don't understand the line of code

Posted 20 October 2012 - 10:25 AM

creativecoding, on 19 October 2012 - 08:30 PM, said:

1. You can just use SELECTED. That's what I prefer, anyways.

2. It looks as if the original programmer was trying to convert the month from it's number format to the spelled equivalent (IE "12" == "December"). Not only is this a bad way of doing things, but it's also very poorly written. This snippet will return the month's name, where $month is the month's number:

date('F', mktime(0, 0, 0, $month));

EDIT:

Oh, it looks like you're trying to make the code smaller... Anyways, you can use this function:

Thank you for the better use of Month, will add that to the program. However I was using this only as the simplest and quickest example. There are numerous places in the code where using a function with a pre-defined array is easier and better than specifying every option line in the code.

A bit of background - this started many years ago as a senior class project (no, I wasn't the instructor. if I had been, the students would have flunked the project for crappy code, but they were beginners afterall) which someone thought was fantastic for a very small company. Functionality has grown and I'm trying to mitigate some of the original problems.

A good example of what I'm trying to eliminate is 4 identical drop-downs with over 100 items. Put the items in an array, invoke using the function, and life is so much simpler.

So, I've learned today (and thank you all, it's always good to learn something new) that I don't need the selected="selected" phrase. But I'm still baffled why each option has SELECTED. I was under the impression that only 1 SELECTED was allowed, and that was the default if the used didn't choose another option from the drop-down.

I've got this working as a stand-alone test case, but the selected value doesn't seem to be retained in the $_POST array for later use in the production code and written to the database.