teng84 Posted August 27, 2007 Share Posted August 27, 2007 well i made this function and i dont want it as a class because it to short but im planing to extend this in my class db now can anybody point me or suggest better way of doing this i need ideas plzzz no wrong and correct answer i love hearing ideas form other person function dropmenu($arrvalue,$selected){ foreach($arrvalue as $key=>$value){ $selected_value = ($selected == $key)?'selected':''; $stroption .= "<option value='".$key."' $selected_value>".$value."</option>\n"; } return $stroption; } function _month($selected){ $months = array(1=>'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); return dropmenu($months,$selected); } function _day($selected){ $day = array(range(0,31)); unset($day[0][0]); return dropmenu($day[0],$selected); } function _year($selected){ $year_key = array(range(1950,2008)); $year_value= array(range(1950,2008)); $year = array_combine($year_key[0], $year_value[0]); return dropmenu($year,$selected); } Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/ Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 i need somebody to comment its only me whos seeing my work so idont know if im doing great Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334832 Share on other sites More sharing options...
dbo Posted August 27, 2007 Share Posted August 27, 2007 Besides looking at your code... why don't you tell us the problem you're trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334833 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 no problem i want to know if the way i declare an array etc is fine and the way i do this is fine also i have this feeling that its good but i need somebody to add some critics on me or yell at me for my stupid code Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334834 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 if some member here need a drop menu for the dates or even for database result u can use this but note i use this in smarty template(which i hate) well that is only if you find this one useful Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334836 Share on other sites More sharing options...
dbo Posted August 27, 2007 Share Posted August 27, 2007 The code you have there is fine.... but without knowing what you ultimately want to do it's hard to offer much else. Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334838 Share on other sites More sharing options...
AndyB Posted August 27, 2007 Share Posted August 27, 2007 One obvious improvement would be that in just over 4 months, it's going to be out of date. Setting the year range to extend to date("Y") would solve that. Also since more people are likely to want recent years than years from my youth, you might want to invert the order of the years to save scrolling Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334840 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 date("Y") this is coolll ;D ;D this is what im talking about each of us has a diff idea thanks bro is there any ? Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334841 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 Just to add to what Andy said, I usually use date("Y") and then date("Y")-100 (or whatever) for the whole year range. That way it always adjusts for the new year, and you won't end up with 1900-2020 in a few years. Since you've made a drop down menu function, you might consider working on other form functions. I have a class I use for any form, which handles error checking, etc. So if I want an input field I just use it. function finput($label, $id, $value=""){ print '<label for="'.$id.'">'.$label.': </label><input type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'" />'; } Etc. You can also add in stuff like if the field is required and save it to an array, so your error checking is faster/automated. Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334847 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 Just to add to what Andy said, I usually use date("Y") and then date("Y")-100 (or whatever) for the whole year range. That way it always adjusts for the new year, and you won't end up with 1900-2020 in a few years. Since you've made a drop down menu function, you might consider working on other form functions. I have a class I use for any form, which handles error checking, etc. So if I want an input field I just use it. function finput($label, $id, $value=""){ print '<label for="'.$id.'">'.$label.': </label><input type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'" />'; } Etc. You can also add in stuff like if the field is required and save it to an array, so your error checking is faster/automated. thanks but i prefer to use required param but wait do you think its better to use php to generate input type i guess it will slow down the site a bit just a guess in my case i normally separate html with php as possible as i can but in you case it seems like youre letting php to do this for you any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334850 Share on other sites More sharing options...
Jessica Posted August 27, 2007 Share Posted August 27, 2007 Why would I waste time writing the same code over and over when I can have a function do it once? Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334851 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 yah i guess i use this sample you gave me if i will use notepad lol any way function finput($label, $id, $value=""){ print '<label for="'.$id.'">'.$label.': </label><input type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'" />'; } date("Y") and then date("Y")-100 (or whatever) <---good, nice and better i guess for now i can use this using the check boxes ya know to delete the checked one Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334855 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 is there a better way to range a month in an array Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334868 Share on other sites More sharing options...
keeB Posted August 27, 2007 Share Posted August 27, 2007 http://php.net/mktime int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) $cur_month - 1 Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334959 Share on other sites More sharing options...
teng84 Posted August 27, 2007 Author Share Posted August 27, 2007 dude thats longer than my code i guess i have to use mine also its slower right? Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-334963 Share on other sites More sharing options...
Barand Posted August 27, 2007 Share Posted August 27, 2007 function _day($selected){ $day = array(range(0,31)); unset($day[0][0]); return dropmenu($day[0],$selected); } range returns an array, so you don't need array(range(0,31)) function _day($selected){ $day = range(0,31); unset($day[0]); return dropmenu($day, $selected); } Quote Link to comment https://forums.phpfreaks.com/topic/66806-i-need-smart-people-here/#findComment-335089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.