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