kmark Posted June 18, 2008 Share Posted June 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110794-year-menu-function/ Share on other sites More sharing options...
Barand Posted June 18, 2008 Share Posted June 18, 2008 My ESP quotient is even lower than my IQ, so if you like to tell us what's in the table and how you can can tell if a goal was met, then perhaps we can help Quote Link to comment https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568479 Share on other sites More sharing options...
kmark Posted June 18, 2008 Author Share Posted June 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568489 Share on other sites More sharing options...
Barand Posted June 18, 2008 Share Posted June 18, 2008 But only the add the years that they have completed goals in. It actually has nothing to do with whether the goal was met. ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568496 Share on other sites More sharing options...
kmark Posted June 18, 2008 Author Share Posted June 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/110794-year-menu-function/#findComment-568505 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.