Jump to content

I need smart people here


teng84

Recommended Posts

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);
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.