Jump to content

Year Menu Function


kmark

Recommended Posts

Im a trying to write a function that will look through a database to see if a user has completed previous goals in the last 3 years and if so add those years to the drop down menu. But only the add the years that they have completed goals in.

 

I can't think of an efficient way to do this  other that looping through the database 3 times.  Is there a better way?  Code is below

 

//====================================
//Year Menu Function
//====================================
function yearMenu($session){
$menu = '<select name="year">';//Add beginning select tag
$thisYear = date("Y");
$sql = "SELECT * FROM tblGoals WHERE userID = '$session'";
$result = $db->Execute($sql);
if($result->RecordCount() == 0){//No Previous Years so just show this year
	$menu .= '<option value="'.thisYear.'">'.$thisYear.'</option>';
}else{
	while(!$result->EOF){
	NEED HELP HERE
		$result -> MoveNext();		
	}	
}
$menu .= '</select>';//Add closing select tag
return $menu
}

 

Any help is appreciated

Link to comment
https://forums.phpfreaks.com/topic/110794-year-menu-function/
Share on other sites

It actually has nothing to do with whether the goal was met.  All I need as I said is it to look though the database and find if there are any goals entered where the year matches the any of the last 3 years (there is a field called "year" in the database). Then the tricky part which is to have the years matched (for example 2006 and 2008) and put them in the menu:

 

<option value="2006">2006</option>

<option value="2008">2008</option>

 

I can think of a way to do this which would be to loop through the database 3 times searching far each different year each time, but i'm am wondering if i could do this one query.

 

Link to comment
https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568489
Share on other sites

OK...So back to basics.

 

Users Enter goals for any given year (example: 2004, 2006, 2007).  They didn't have to enter them for every year.

 

So then at the main page i want to have a drop down menu that only display the years that they have completed goals for if they are in the last 3 years.

 

The output in this example would be

 

<select name="year">

<option value="2006">2006</option>

<option value="2007">2007</option>

</select>

 

I hope this helps clarify

 

Link to comment
https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568505
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.